Versions Compared

Key

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

...

Wiki Markup
Autoboxing on the other hand, can also produce subtle effects. It works by automatically wrapping the primitive type to the corresponding wrapper object. Some care should be taken during this process, especially when performing comparisons. The Java Language Specification \[[JLS 2005|AA. Java References#JLSBibliography#JLS 05]\] explains this point clearly:

...

Wiki Markup
This noncompliant code example (adopted from \[[Bloch 2009|AA. Java References#BlochBibliography#Bloch 09]\]), defines a {{Comparator}} with a {{compare()}} method. The {{compare()}} method accepts two boxed primitives as arguments. 

...

Wiki Markup
\[[Bloch 2009|AA. Java References#BlochBibliography#Bloch 09]\] 4. "Searching for the One"
\[[Pugh 2009|AA. Java References#PughBibliography#Pugh 09]\] Using == to compare objects rather than .equals

...