Again, this is not the case in Java. If we call `Optional.get()` when no value is present, a NoSuchElementException is thrown. This defeats the purpose entirely! We're essentially trading one unchecked exception for another.
Java 8’s new Optional type is worthless
W. Brian Gourlie

I’ll be the first to agree that Oracle should have done more with Optional et al in Java 8. However this is missing the point of Optional: thankfully they relented and included flatMap, which allows you to stay in Monad-land and write completely null-safe code:

Object out = Optonal.ofNullable(in).flatMap(fn1).flatMap(fn2).flatMap(fn3).orElse(DEFAULT);

Here fn[123] will only be invoked with a non-null, i.e. present value, even if the previous stage returns null. If you are going to use #ifPresent(), you might as well surround your code in a if-not-null check and skip Optional altogether.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.