Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

It is because that in JDK 5.0, if the value p being boxed is true, false, a byte, an ASCII character, or an integer or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2. And the reason for this rule explained in criterion for autoboxing:In case of that, when we need to do some comparison of these wrapper class, we should use equal instead "==":

Compliant solution


 "Ideally, boxing a given primitive value p, would always yield an identical reference. In practice, this may not be feasible using existing implementation techniques. The rules above are a pragmatic compromise. The final clause above requires that certain common values always be boxed into indistinguishable objects. The implementation may cache these, lazily or eagerly."

...