O'Reilly logo

Java 8 in Action: Lambdas, streams, and functional-style programming by Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. Using Optional as a better alternative to null

This chapter covers

  • What’s wrong with null references and why you should avoid them
  • From null to Optional: rewriting your domain model in a null-safe way
  • Putting optionals to work: removing null checks from your code
  • Different ways to read the value possibly contained in an optional
  • Rethinking programming given potentially missing values

Raise your hand if you ever got a NullPointerException during your life as a Java developer. Keep it up if this is the Exception you encounter most frequently. Unfortunately, we can’t see you at this moment, but we believe there’s a very high probability that your hand is raised now. We also guess you may possibly be thinking something like “Yes, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required