Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static <T> T nullSafe(Supplier<T> supplier, T fallback) {
- try {
- T result = supplier.get();
- return result != null
- ? result
- : fallback;
- } catch (NullPointerException npe) {
- return fallback;
- }
- }
Add Comment
Please, Sign In to add comment