3 ms·
.valueOf() will sometimes give different instance, sometimes not. If you want a instance, I recommend new :)
by paulddraper 3y ago
.valueOf() will sometimes give different instance, sometimes not.
If you want a instance, I recommend new :)
- monocasa 3y agoWell, unfortunately autoboxong will silently call valueOf(). So Integer val1 = 5; Integer val2 = 5; Integer val3 = 200; Integer val4 = 200; will have you ending up with val1 and val2 being equal with ==, but val3 and val4 won't be. The general reply is 'you're holding it wrong', but that doesn't make it any less absurd. That's what the PHPers say about "123" < "456A" < "78" < "123".
- paulddraper 3y agoIDK it makes sense to me. Unless you call `new` there's no guarantee that you have a different object.