Optional is used to represent nullable object, Some uses of this class include
Compared with Guava, one annoying problem with java.util.Optional is that it does not provide a method like
orElse(Optional
which is, on the other hand, defined in com.google.common.base.Optional as
or(Optional
The lack of this specific feature limits monadic applications of Java 8's Optional.
UPDATE:
Guava's or(Optional can be replicated as in with Java 8 Optional as
optionalA.map(Optional::of).orElse(optionalB)
or
optionalA.map(Optional::of).orElseGet(() -> computeOptionalB)
UPDATE:
In Java 9 (finally!) you'll be able to use Optional.or(Supplier:
optionalA.or(() -> computeOptionalB)
That's neat!