Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class Magician {
public Magician(){}
public Magician(String name){
this.name = name;
}
public String getName() {
return name;
}
String name;
}
Magician magician = new Magician("Miracle Max");
Optional<Magician> optMagician = Optional.ofNullable(magician);
if (optMagician.isPresent())
return optMagician.get(); //returns a Miracle Max Magician
else
System.out.println("Miracle Max isn't home.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.