Skip to content

Instantly share code, notes, and snippets.

@scottashipp
Created January 3, 2019 16:01
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 scottashipp/03c2c9aeae14b6003c6047a006472cac to your computer and use it in GitHub Desktop.
Save scottashipp/03c2c9aeae14b6003c6047a006472cac to your computer and use it in GitHub Desktop.
Snippet from a popular open-source Java tool showing Optional.isPresent() checking in place of null-checking
Optional<String> pathsStr = get(PATHS_KEY);
if (pathsStr.isPresent()) {
ObjectMapper objectMapper = new ObjectMapper();
try {
String[] paths = objectMapper.readValue(pathsStr.get(), String[].class);
// ... the rest elided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment