Quantcast
Channel: Why should Java 8's Optional not be used in arguments - Stack Overflow
Viewing all articles
Browse latest Browse all 29

Answer by Chris Happy for Why should Java 8's Optional not be used in arguments

$
0
0

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).


Viewing all articles
Browse latest Browse all 29

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>