`Boolean` constructor is inefficient, consider using `Boolean.valueOf` insteadJAVA-S0066
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);
Recommended
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
- Spotbugs - DM_BOOLEAN_CTOR