WARNING: This server is unstable and will be retired in the next days.
If you want to keep this forum available, please request immediately a migration
on the Nabble Support forum.
Forums that don't receive any migration request will be deleted forever.
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.