java.util.Optional
ImagineOptional
as a container that may or may not contain some value. Just like all references in Java can point to some object or be null,Option
may enclose some (non-null!) reference or be empty.
Optional
instead of plain null is statically checked at compile time and much more informative as it clearly indicates that a given variable may be present or not. Of course it requires some discipline - you should never assign null to any variable any more.