Skip to content

Instantly share code, notes, and snippets.

Created Aug 12, 2016
What would you like to do?
// Avoid NPE simply taken from :
public static <T> Optional<T> resolve(Supplier<T> resolver) {
try {
T result = resolver.get();
return Optional.ofNullable(result);
catch (NullPointerException e) {
return Optional.empty();
Usage :
resolve(() -> obj.getNested().getInner().getFoo()).ifPresent(System.out::println);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment