Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
kfish568y@maximizer oh not at all, but it's still used way too often with objects. But its interesting that you'd expect certain behaviors from primitives, but their delegate object has its own perks.
-
One of the first things I learned in school in Java class: use the equals method instead of == operator. For reasons like these I do add value to a solid educational background in software engineering.
-
kfish568yMost definitely, however , with this knowledge of the cache, one can actually modify cached integer values, albeit within its own context. But if I can inject code to a Java module, I can make it think 3 is actually 20. It's neat.
Related Rants
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 :)
undefined
integer
cache
testing
mildly interesting
java