3 ms·
With Java 8 having Optional and Lambdas, this is no longer the case: final Optional<String> myOptionalVar = functionThatReturnsOptional(); final String
by pvorb 10y ago
With Java 8 having Optional and Lambdas, this is no longer the case:
final Optional<String> myOptionalVar = functionThatReturnsOptional();
final String output = myOptionalVar
.map(str -> str.length() > 10
? "This is a long string."
: "This is a short string.")
.orElse("This code would be fifteen lines of null checking in Java.");
System.out.println(output);