3 ms·
I assume you are referring to the java.lang.Integer box caching situation, which is indeed shitty. However as you've written it, that will always evaluate to t
by jcdavis 9y ago
I assume you are referring to the java.lang.Integer box caching situation, which is indeed shitty. However as you've written it, that will always evaluate to true, as it unboxes, adds 1 to each side, and compares the int values, not the references. To get what I assume you are talking about, you need something like:
Integer b = a+1;
Integer c = a+1;
b==c
Which by default returns true for a=126 but false for a=127. A bad situation for sure, but thankfully pretty much every static analysis tool will spot that.
- bunderbunder 9y agoYes, you're right. Thanks for correction.