If wanting an optional primitive type, just use the primitive's class.
For those coming from a C++ background and got confused.
E.g. for an optional boolean
, use Boolean
.
The biggest problem is that Optional<Boolean>
itself could be set to null, so now you have three states instead of two.
E.g. Optional<Boolean>
can be (null, empty, or not-empty) but Boolean
can only be (null or non-empty).