Everything about

#optional

A series of posts that give you more insight into one of Java's more misunderstood and misused features as well as discussions related to it and its updates in future versions.

I wrote a series of posts about Optional that I recommend you read in the following order:

Image with slug intention-revealing-code-java-8-optional
Intention Revealing Code With Optional#post#clean‑code #java‑8 #optional
Write intention revealing code with Java 8's new type Optional and prevent most NPEs. This is not optional!
Image with slug design-java-optional
The Design of Optional#post#java‑next #java‑8 #optional
A digest of how Optional was introduced in Java 8, summarizing the many discussions about it and their key points based on the mail archive of JSR-335.
Image with slug why-isnt-java-optional-serializable
Why Isn't Optional Serializable?#post#java‑next #java‑8 #optional #serialization #primitive‑classes
Discussing the reasons for not making Java 8's new type Optional serializable.
Image with slug serialize-java-optional
Serialize Optional#post#java‑8 #optional #serialization
A summary of why you can't serialize Optional and what can be done to deal with that limitation if necessary.

Then there are a few more posts on the topic that can be read in pretty much any order:

Image with slug inside-java-newscast-64
(Dirty?) Tricks in Java 22 - Inside Java Newscast #64#video#pattern‑matching #optional #clean‑code
Pattern matching Optional, expanding sealed type hierarchies, nesting switches, reverting instanceof, and more - so many (dirty) tricks to play around with in modern Java
Image with slug java-optional-opinions
More Opinions On Optional#post#optional
How much work is it to wrap Optional? Do you need to null-check Optional arguments? What about serializability and framework support? And why consider the type in the first place? Answers in here!
Image with slug inside-java-newscast-19
Where to use Optional - Inside Java Newscast #19#video#optional
Is it ok to use Optional as parameter type? Overloading is an alternative, but how well does it stack up? Thoughts on this question (and other Optional-related ones) can usually be put into one of three (and a half) categories.
Image with slug inside-java-newscast-7
Handling null and Upgrading Past Java 8 - Inside Java Newscast #7#video#migration #optional #switch #project‑valhalla
Dealing with null is never fun, so in this newscast, I explain how to best handle it, what tools can do, and how recent and upcoming language changes help dealing with it. I'll also look at a recent blog post about how Netflix upgraded from Java 8 to 16.
Image with slug talk-just
Why Don't They Just... ?! The Deliberations Behind Evolving Java#talk#streams #optional #records #collections
There are many nifty features that Java could have but doesn't. Somewhat surprisingly, there are reasons for that and in this talk I'll discuss those for a few concrete cases as well as the deliberations behind such decisions.
Image with slug 25h-brian-goetz
Java's Quirks and Wrong (?) Defaults with Brian Goetz#video#conversation #migration #optional #serialization
Mutability, nullability, serialization, primitives - Nicolai Parlog discusses with Java language architect Brian Goetz why Java is the way it is.
Image with slug java-9-tutorial
Code-First Java 9 Tutorial#post#java‑9 #migration #streams #optional #collections #j_ms
Showing code for the most important Java 9 features: private interface methods, stream and optional APIs, collection factories, reactive streams, stack walking, multi-release JARs, redirected platform logging, unified logging, the module system, and more. If you're new to Java 9, start here.
Image with slug talk-expert-java-8
Expert Java 8#talk#java‑8 #lambda #streams #optional #default‑methods
With this talk, I help you get the most out of lambdas, Streams, Optionals, and default methods, helping you master Java 8's core features
Image with slug why-elvis-should-not-visit-java
Why Elvis Should Not Visit Java#post#clean‑code #optional #rant
The desire for the Elvis operator for easier null-handling echoes through the Java community. But due to Java's type system, it should never be introduced!
Image with slug java-9-optional
Java 9 Additions To Optional#post#java‑9 #optional
Java 9 is coming! One of the changes are new methods on Optional: stream(), or(), and ifPresentOrElse(), which considerably improve Optional's API.
Image with slug stephen-colebourne-java-optional-strict-approach
Java 8 SE Optional, a strict approach#post#java‑8 #optional
Stephen Colebourne presented his pragmatic approach to using Optional. I argue for a stricter one that gets us further without considerable downsides.
Image with slug casting-in-java-8-and-beyond
Casting In Java 8 (And Beyond?)#post#java‑8 #optional #streams
Proposal to implement new casting methods on Java's Class. They aim to fulfill the need for improved ways to cast which was created by Java 8.
Image with slug java-pirate-elvis-operator
Roll Your Own Pirate-Elvis Operator#post#java‑8 #lambda #optional
Java has no Elvis operator (or null coalescing operator / null-safe member selection) but with lambda expressions / method references you can roll your own.