Created
January 30, 2017 12:38
-
-
Save struberg/5d1182c230c357a2ab59135cd30a84a6 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 Optional<String> getDings() { | |
String dings = ...; | |
return Optional.ofNullable(dings); | |
} | |
public void usageWithOptional(Optional<String> val) { | |
String x = val.orElse("defaultValue"); | |
or | |
String x = val.get() // and boom if missing instead of Validate.notNull | |
} | |
public void usageWithoutOptional(String val) {... } | |
... | |
public void callIt() { | |
Optional<String> myval = getDings(); | |
usageWithOptional(myval); | |
usageWithoutOptional(myval.orElse( "bla") or myval.get() ); ??? hell, I don't like that | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment