Versions Compared

Key

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

...

In JDK 1.6.0_10, the output of this code is 0. In this code, we want to count the same numbers of array list1 and array list2. Undoubtedly, the result is not the same as our expectation. Owning to the fact that the Integer can only caches from -127 to 128, so when int number beyond this range, it will be autoboxed into different objects, then the "==" will return false. But if we can set more caches inside Integer (cach cache all the integer value (-32K-32K), which means that all the int value could be autoboxing autoboxed to the same Integer object) then the result may be different!

...