Java 8’s new Optional type is worthless
W. Brian Gourlie

First of all, the Optional type was never meant to be used outside the Streams API (even though the fact that it’s located under java.util seems to suggest otherwise).

Then, why would you call Optional.get()? For handling optionals call .orElseGet() or .orElseThrow() to handle the optional value (or .map() or .flatMap() depending on the circumstances). Calling .get() is (almost) always wrong.

Yes the optional can be null but this is a bug which you will uncover the moment you try to handle the Optional value. Still better than passing a null value around which blows up in another part of your program.

I still agree that the Optional type in Java 8 is a subpar solution. If you want first class support use Kotlin or Scala.

One clap, two clap, three clap, forty?

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