View difference between Paste ID: YS6X9Tub and 6KTRtgfB
SHOW: | | - or go back to the newest paste.
1
public static <T> T nullSafe(Supplier<T> supplier, T fallback) {
2
        try {
3
            T result = supplier.get();
4
            return result != null
5
                    ? result
6
                    : fallback;
7
        } catch (NullPointerException npe) {
8
            return fallback;
9
        }
10
    }