Created
December 13, 2016 17:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adres.setStreet(nullSafeGet -> person.getAddress().getStreet()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment