Skip to content

Instantly share code, notes, and snippets.

@devnoo
Created December 13, 2016 17:30
Show Gist options
  • Save devnoo/0d1b54fa4e8a767915e0ac7985acfef1 to your computer and use it in GitHub Desktop.
Save devnoo/0d1b54fa4e8a767915e0ac7985acfef1 to your computer and use it in GitHub Desktop.
bit of a hack to get rid of all null checks in deeply nested properties
import java.util.function.Supplier;
public class NullSafeUtils {
public static <T> T nullSafeGet(Supplier<T> supplier){
try{
return supplier.get();
}catch (NullPointerException npe){
return null;
}
}
}
adres.setStreet(nullSafeGet -> person.getAddress().getStreet())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment