Java's Optional has a Problem
Java’s Optional is over a decade old, and has been subject to intense debate since long before its release. With this in mind, I will argue a particular aspect of its design was a rather unfortunate mistake, and show how it can lead to bugs. I will moreover discuss potential mitigations, and what a better design could have looked like. While tangentially related, this post is not about Optional not being a monad. For more on that, I refer you to this somewhat famous comment on the OpenJDK mailing list. Key excerpt: “(…) but the goal [with Optional] is NOT to create an option monad or solve the problems that the option monad is intended to solve.” ...