Skip to content

Instantly share code, notes, and snippets.

Avatar

Khurrum Nasim knasim

  • let the machine write it
  • washington dc
View GitHub Profile
View gist:09069e2a984a2e3f1598700e2df572a5

Java 8: java.util.Optional

private abstract Optional<String> methodThatReturnsOptionalString();

private void useOptionalString() {
	Optional<String> myOptionalString = methodThatReturnsOptionalString();
	if (myOptionalString.isPresent()) {
		String myUnboxedString = myOptionalString.get();
		System.out.format("Optional string had value: %s\n", myUnboxedString);

} else {