20th Oct 2017, 12:30 PM
Simple Guy
Simple Guy - avatar
1 Resposta
+ 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
20th Oct 2017, 2:29 PM
Kirk Schafer
Kirk Schafer - avatar