Skip to content

Instantly share code, notes, and snippets.

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 benweidig/1eb74b5587f8c853dd17e83b490c681f to your computer and use it in GitHub Desktop.
Save benweidig/1eb74b5587f8c853dd17e83b490c681f to your computer and use it in GitHub Desktop.
Optional<String> withValue = Optional.of("definitly a string");
String s1 = withValue.get();
Optional<String> noValue = Optional.empty();
String s2 = noValue.get();
// ^^^^^^^^^^^^^ this throws NoSuchElementException!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment