peter.levart at marand.si
Sun Mar 25 23:39:52 PDT 2012
On Sunday, March 25, 2012 06:37:00 PM Brian Goetz wrote:
> > OK, so this is simply an implementation hack, which happens to improve
> > performance, and has the side effect of probably confusing new users,
> > rather than a deliberate, unreliable design feature?
> Which is almost identical to something we do in javac -- fold together
> identical string literals within a class into the same constant pool
> entry, resulting in strings appearing to be == accidentally.
I allways thought this was a feature not an accidential consequence. It's
written down in the String's javadoc as:
"All literal strings and string-valued constant expressions are interned.
String literals are defined in §3.10.5 of the Java Language Specification"
So perhaps we are talking about two different things here:
1) identical strings in the same class are folded into the same constant pool
entry (as optimization of class file size)
2) string literals are interned (as a language/library feature)
The fact that identical literal strings apear to be == is therefore a language
feature, not an optimization side-consequence.
> We don't
> do it to confuse the users, but it may have that effect anyway.
More information about the lambda-dev