Skip to content

Instantly share code, notes, and snippets.

@MarkyC
Created July 23, 2018 20:42
Show Gist options
  • Select an option

  • Save MarkyC/441a9413f9ce8d06051de693502ca1c2 to your computer and use it in GitHub Desktop.

Select an option

Save MarkyC/441a9413f9ce8d06051de693502ca1c2 to your computer and use it in GitHub Desktop.
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment