Skip to content

Instantly share code, notes, and snippets.

@poetix
Last active December 6, 2017 17:08
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 poetix/828654fae68955c4d04652c064c4df34 to your computer and use it in GitHub Desktop.
Save poetix/828654fae68955c4d04652c064c4df34 to your computer and use it in GitHub Desktop.
public String ofNullableExample(Map<String, String> map) {
return Optional.ofNullable(map.get(key))
.orElseThrow(() -> new ItemNotFoundException(key));
}
public String nullCheckingExample(Map<String, String> map) {
String valueAtKey = map.get(key);
if (valueAtKey == null) {
throw new ItemNotFoundException(key);
}
return valueAtKey;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment