A response to Stephen Colebourne's pragmatic approach to Java 8 Optional, arguing for a stricter usage pattern. While Colebourne recommends using null internally within classes and only exposing Optional via getters, the author advocates for using Optional as field types and constructor/setter parameters to eliminate null entirely. The post compares both approaches with code examples, addressing concerns around performance (profile first), serializability (solvable), convenience (use method overloading), and JavaBeans compatibility. The conclusion is that the stricter approach better leverages the type system to prevent null-related bugs with minimal downsides.
Sort: