Last active
July 7, 2016 04:49
-
-
Save afcastano/551fb83194a299d8e3823686b307ad18 to your computer and use it in GitHub Desktop.
Add two optionals in Java
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 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