Optional in Java

Viraj Turakhia
Decaffeinating Java
1 min readMar 15, 2020

A colleague of mine once said:

“The more I read about Optional, the more I like it.”

And another colleague of mine said:

“Optional initiative is overwhelming. You should give some space to us.”

So apparently, a small dose of Optional is easier to digest than one long tutorial. So here we go!

  1. Use Optional when a method returns null : Talks about different ways in which Optional can be used while calling a method that can potentially return a null value.
  2. Deprecating @Nonnull and @Nullable annotations : Shows why these annotations are no longer needed after the introduction of Optional in Java 8.

--

--

Viraj Turakhia
Decaffeinating Java

A software engineer with 17 years of experience and still learning.