Java boolean
allows values of true
and false
while Boolean allows true
, false
, and null
. I have
I almost never use Boolean
because its semantics are vague and obscure. Basically you have 3-state logic: true, false or unknown. Sometimes it is useful to use it when e.g. you gave user a choice between two values and the user didn't answer at all and you really want to know that information (think: NULLable database column).
I see no reason to convert from boolean
to Boolean
as it introduces extra memory overhead, NPE possibility and less typing. Typically I use awkward BooleanUtils.isTrue() to make my life a little bit easier with Boolean
.
The only reason for the existence of Boolean
is the ability to have collections of Boolean
type (generics do not allow boolean
, as well as all other primitives).
I suppose in some case, you should have a mechanism to distinguish a Boolean field which already set value or not.