Skip to content

Instantly share code, notes, and snippets.

@afcastano
Last active July 7, 2016 04:49
Show Gist options
  • Save afcastano/551fb83194a299d8e3823686b307ad18 to your computer and use it in GitHub Desktop.
Save afcastano/551fb83194a299d8e3823686b307ad18 to your computer and use it in GitHub Desktop.
Add two optionals in Java
public Optional<Integer> optionalAdd(Optional<Integer> val1, Optional<Integer> val2) {
if(val1.isPresent() && val2.isPresent()) {
return Optional.of(val1.get() + val2.get());
}
return Optional.empty();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment