Sr. Enterprise Architect at Devtech Belgrade, Serbia. A Java Champions, Oracle Groundbreakers ambassador, Adopts Java SE 9, 10, and what is next, Java EE 7, 8 & JavaFX, JCP member, Was JCP Executive Committee member, JSR 354, 363 & 373 Expert Group member, EGJUG leader, Oracle Egypt Architects Club board member, speaks Java, love IoT / Mobile/ Web / Big Data / Cloud / Blockchain / DevOps, international speaker, Books Author of “JavaFX essentials”, “Getting started with clean code, Java SE 9”, and “Hands-On Java 10 Programming with JShell”, Won Duke’s choice 2015, 2014 awards, and JCP outstanding adopt-a-jar participant 2013 awards, IoT Geek.
Working on my new big project book “Secrets of a Java Champion”, and new publications for IBM DevelopersWork.
10 years of speaking Many conferences including in Devoxx UK, Belgium, Morocco, VoxxedDays Istanbul, Romania, Romania, JFokus, JavaOne 6 times, Oracle Code, Oracle OpenWorld, JavaDays Ukraine, JavaZone, GeeCon Poland, Code Europe, GDG, Google DevFest, Devnexus Atlanta, DWX Germany.
25+ recipes to use Optional Effectively which Is Not Optional
So, what did the VP of TPM do wrong? Additionally, what did the code reviewer and developer do wrong? Well, the answers are at the end of this session, but if you didn’t intuit that the code that will go into production is still open for NPE, then maybe this article is for you. And, yes, somehow the code passed the testing phase as well. The best way to use things is to exploit them for what they have been created and tested for in the first place. Java 8 Optional is not an exception to this rule.
The purpose of Java 8 Optional is clearly defined by Brian Goetz, Java’s language architect: Optional is intended to provide a limited mechanism for library method return types where there needed to be a clear way to represent “no result,” and using null for such was overwhelmingly likely to cause errors.
So, how to use Optional the way it was intended? Typically, we learn to use things by learning how to not use them, and, somehow, this is the approach here as well. So, I will tackle this topic through 25+ recipes. This is a suite of recipes that try to address Optional in your code through an elegant and painless approach.