Last active
December 6, 2017 17:08
-
-
Save poetix/828654fae68955c4d04652c064c4df34 to your computer and use it in GitHub Desktop.
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
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