4 ms·
IIRC, this cache only works if you use Integer.valueOf instead of the constructor. (I could be misremembering, but the reason for that seems obvious to me.)
by eropple 15y ago
IIRC, this cache only works if you use Integer.valueOf instead of the constructor. (I could be misremembering, but the reason for that seems obvious to me.)
- masklinn 15y ago> the reason for that seems obvious to me. That Java's semantics force new object creation on constructor call, it's not possible to do otherwise (as opposed to, say, JavaScript, Python or Ruby in which object creation can be overridden and the "constructor" work like a factory methods, when it isn't one outright) (which it is in Python and Ruby)
- eropple 15y agoYes, exactly.