Autoboxing is rather scary. While I fully understand the difference between ==
and .equals
I can\'t but help have the follow bug the hell out of m
Integer
s in the byte range are the same object, because they are cached. Integer
s outside the byte range are not. If all integers were to be cached, imagine the memory required.
And from here
The result of all this magic is that you can largely ignore the distinction between int and Integer, with a few caveats. An Integer expression can have a null value. If your program tries to autounbox null, it will throw a NullPointerException. The == operator performs reference identity comparisons on Integer expressions and value equality comparisons on int expressions. Finally, there are performance costs associated with boxing and unboxing, even if it is done automatically