Skip to content

Instantly share code, notes, and snippets.

@mjedynak
Created April 1, 2018 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjedynak/34e3f2fa2ab8fa1221685c2f4925a02c to your computer and use it in GitHub Desktop.
Save mjedynak/34e3f2fa2ab8fa1221685c2f4925a02c to your computer and use it in GitHub Desktop.
public class CityRetrieverWithOptional {
private final PersonService personService;
public Optional<String> retrieveCity(String name) {
return Optional.ofNullable(personService.getByName(name))
.map(Person::getAddress)
.map(Address::getCity);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment