Java logoJava/
JAVA-S0066

`Boolean` constructor is inefficient, consider using `Boolean.valueOf` insteadJAVA-S0066

Major severityMajor
Performance categoryPerformance

Creating new instances of java.lang.Boolean wastes memory, since Boolean objects are immutable and there are only two useful values of this type.

Examples

Problematic Code


Boolean a = new Boolean(true);

Use the Boolean.valueOf method (or autoboxing since Java 1.5) to create Boolean objects instead.


Boolean a = true;

// or

Boolean b = Boolean.valueOf(true);

Note - This issue will be ignored within tests.

References