3 ms·
"new string" is rather misleading here. But the string _is_ new; there was no object that was Object.Equals to it before the call. That new string just never f
by Someone 13y ago
"new string" is rather misleading here.
But the string _is_ new; there was no object that was Object.Equals to it before the call. That new string just never forgets where it came from.
e.g. make people write .substring(n).view() or .substring(n).copy() or similar.
That's what people have been doing for years: .substring(n) versus new String(substring(n)) (and, as a third option: .substring(n).intern())
I find it weird that this change is made because, as a side-effect, they almost have to start optimizing "new String(s)" calls. With this change, the only thing that can be useful for is for creating a String that is the same as another String, but not equal to it. I think that aspect of that call is rarely, if ever, used. If one can proof that it is never used, the next step on this path would be to make that call into a no-op. If one cannot proof it, it still would likely be a good speed up, but it also would be extremely risky.