AboutWeb, Android, Windows dev
Joined devRant on 6/26/2016
Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
Less rant, more mildly interesting Java trivia.
Integer i0 = 3; Integer i1 = 3;
Integer i2 = 300; Integer i3 = 300;
i0 == i1 is true as expected
i2 == i3 is actually false
Java caches -128 to 127 Integer objects for faster perf so when you're inside that range, the objects are indeed the same, but because == checks object equality, the Integer outside of the range is not cached and had to be initialized, so i2 and i3 are two different objects.
You can totally break some tests this way :)9