Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: changed the Boolean CS to show that Boolean.TRUE compares equal to the autoboxed primitive true

...

Compliant Solution (Boolean)

In this compliant solution, the values of autoboxed Boolean.TRUEBoolean.FALSE, or the values of autoboxed Boolean variables may be compared using the reference equality operators because the Java language guarantees that the Boolean type is fully memoized. Consequently, these objects are guaranteed to be singletons.

Code Block
bgColor#CCCCFF
public void exampleEqualOperator(){
  Boolean b1 = true; // Or Boolean.True
  Boolean b2 = true; 
	
  if (b1 == b2) {   // Or always equal
    System.out.println("Always printed");
  }
 
  b1 = Boolean.True
	TRUE;
  if (b1 == b2) {   // always equal
    System.out.println("Always printed");
  }
}

...