A deep dive into the debate around Java's Optional type, specifically whether it should be used as a method parameter type. The discussion covers overloading as an alternative (including its pitfalls like combinatorial explosion and null-laden canonical implementations), builders and parameter objects, and a taxonomy of four developer camps: never use Optional, use it only as a return value in limited cases, use it always as a return value, and use it everywhere. The author personally favors the 'Optional everywhere' camp but recommends teams default to the official guidance of using Optional only for return values where absence is error-prone.

10m read timeFrom nipafx.dev
Post cover image
Table of contents
▚ Intro▚ Overloading Instead Of Optional▚ Discussing Optional▚ Optional Camps▚ Outro

Sort: