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 | } |