Skip to content

Instantly share code, notes, and snippets.

@wsoczynski
Created November 6, 2012 14:26
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 wsoczynski/4025014 to your computer and use it in GitHub Desktop.
Save wsoczynski/4025014 to your computer and use it in GitHub Desktop.
Optional 1
class Main {
public Optional<String> someValue = Optional.absent();
public Optional<String> someOtherValue = Optional.of("test");
public static void main(String... arguments){
Main m = new Main();
if(m.someValue.isPresent()){
String foo = m.someValue.get();
System.out.println(foo);
} else {
System.out.println("Some value missing");
}
if(m.someOtherValue.isPresent()){
System.out.println(someOtherValue.get());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment