3 ms·
The "numbers less than 256 are the same objects" wasn't done so you could use "is" on them, that's just a side effect. It was done as an optimization, because
by mark-r 6y ago
The "numbers less than 256 are the same objects" wasn't done so you could use "is" on them, that's just a side effect. It was done as an optimization, because those small integers are far more common than the larger ones. You save space, because you need only one copy of those small integers. And you save time, because those objects are never destroyed or recreated.
- orf 6y agoYes, of course, But I never said that it was done so you could use “is” with them, only that “is” is the wrong thing to do on them.
- roelschroeven 6y agoOf course. "is" is almost always the wrong thing to do.