Created
December 6, 2015 00:04
-
-
Save jmbataller/1f01a2a68bfbdee4453c to your computer and use it in GitHub Desktop.
safe navigator in java 8
This file contains 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
public String getCarInsuranceName(Optional<Person> person) { | |
return person.flatMap(Person::getCar) | |
.flatMap(Car::getInsurance) | |
.map(Insurance::getName) | |
.orElse("Unknown"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment