And why use Boolean.TRUE, if there is already true, is it just to get an object type?

    1 answer 1

    This is done to ensure that for every java.lang.Boolean.valueOf call not to create a new object, but to return a static field of this class.

    • Doesn’t Boolean use a lens pool to create? - pavel
    • Look at the implementation of the class, there is no pool there, instead these fields are used. When autoboxing, valueOf is also called by the way, for the very same purpose - to produce as few new objects as possible. - Artem Konovalov