PS: I understand the difference between \"true\" and true.
Edit: I also understand that Boolean.TRUE is a wrapper for the primitive true, my question then is - why d
Primitive types, (e.i. boolean
), are strongly preferred over classes (e.i. Boolean
) for a number of reasons. See discussion here. https://softwareengineering.stackexchange.com/questions/203970/when-to-use-primitive-vs-class-in-java. Primitive type makes code more readable, prevents pointer errors, such as if(a==b)
vs if(a.equals(b))
, increases performance and follows the conversion.
There is one case when Boolean
or Integer
works better than boolean
and int
. That is if you have a situation when you want to allow null
as a value. This results in a number of null checks, but it prevents false
from slipping through when