+ 3
What?
Whyyyyy? What's the logic of this? https://code.sololearn.com/cgdsDC8guqfy/?ref=app
1 Réponse
+ 6
They're objects; to me it looked like 100 was defined internally already:
Integer a (and b) =1000;
Integer c (and d) = 100;
// different id
System.identityHashCode(a);
System.identityHashCode(b);
// same id
System.identityHashCode(c);
System.identityHashCode(d);
If you run the range -128 to 127, they're all true.
// positive side, (+128 is false; negative: -129 is false)
for(int i=0; i<=128;i++){
Integer c = i, d = i; System.out.println(c == d);
}
Why? https://stackoverflow.com/questions/20897020/why-integer-class-caching-values-in-the-range-128-to-127
First answer says -128 to 127 MUST be cached, additional range MAY be cached, with doc links:
https://stackoverflow.com/a/20948389