| ▲ | papercrane 3 hours ago | ||||||||||||||||
Before value classes this would always be false. The only time comparing Integer objects with == could be true is if Integer object was create by going through Integer.valueOf (or obviously if they were the same object reference.) By default the cached values where -127 to 127, but that is tuneable at runtime.https://github.com/openjdk/jdk/blob/jdk-27%2B27/src/java.bas... | |||||||||||||||||
| ▲ | tsimionescu 3 hours ago | parent | next [-] | ||||||||||||||||
It could also be true if the instances were created through auto-boxing (e.g. arrayList.add(10); arrayList.add(10); arrayList.get(0) == array List.get(1) //would return true, but false if you used 1000 instead of 10). | |||||||||||||||||
| |||||||||||||||||
| ▲ | jmyeet an hour ago | parent | prev [-] | ||||||||||||||||
So you've made my point in showing how complex this is because you're incorrect [1][2]: > By default, Java maintains a cache of Integer objects for values between -128 and +127. [1]: https://stackoverflow.com/questions/3130311/weird-integer-bo... [2]: https://dev.to/marzuk16/understanding-integer-caching-in-jav... | |||||||||||||||||
| |||||||||||||||||