Created
January 2, 2018 20:08
-
-
Save m-x-k/f646aea565927c81dbdd953c42ea6258 to your computer and use it in GitHub Desktop.
Java 9 Optional.or example
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
Optional<String> name = Optional.empty(); | |
Optional<String> alternativeName = Optional.of("john"); | |
name = name.or(() -> alternativeName); | |
name.get(); // Outputs "john" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment