JLS string concatenation clarification
John Rose
john.r.rose at oracle.com
Wed Jan 22 09:28:39 PST 2014
On Jan 21, 2014, at 5:09 PM, Martin Buchholz <martinrb at google.com> wrote:
> The fact that Strings even have an object identity is essentially a bug.
Yes. It is string identity that makes this discussion difficult. In my view, it is possible to work around this by adjusting the spec. This would require great effort, in a phased set of transitions through two or more major releases.
We would have to wean Java users away from using identity operations on strings. Then we can loosen the identity requirements on string factories, allowing the factories to reuse existing strings, something like Integer.valueOf. New documentation would refer to concepts like "values" or "value based types" [1].
[1] http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes/java/lang/doc-files/ValueBased.html
This transition would be irrelevant to over 99.99% of Java programs. But it would cause occasional breakage where some clever programmer, in an unwise moment, decided to "lean on" the semantics of string identity. I'm talking about malapropisms like x = new String("foo") or atrocities like synchronized ("bar"). They would have to be deprecated and then (perhaps) deleted. I have heard credible tales of people synchronizing on globally shared objects like "foo" or Boolean.FALSE or (Integer)42.
It is even possible that we would find it easier to introduce a completely new value-like string type, to co-exist with the old.
I think, in other words, that string identity (and its associated problems) is a tight spot that we might break out of but only with some resolute and tricky maneuvering.
— John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20140122/d45696fc/attachment.html
More information about the compiler-dev
mailing list