Skip to content

Instantly share code, notes, and snippets.

@m-x-k
Created January 2, 2018 20:08
Show Gist options
  • Save m-x-k/f646aea565927c81dbdd953c42ea6258 to your computer and use it in GitHub Desktop.
Save m-x-k/f646aea565927c81dbdd953c42ea6258 to your computer and use it in GitHub Desktop.
Java 9 Optional.or example
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