In the source code of
com.sun.org.apache.xerces.internal.impl.XMLScanner at line 183 and 186
183 protected final static String fVersionSymbol = "version".intern();
186 protected final static String fEncodingSymbol = "encoding".intern();
Why “version” and “encoding” are explicitly interned by using intern() while they are string literals and would get automatically interned?
I’ve tracked down the change to revision 318617 in the Apache Xerces SVN Repository (this is the project where this XML parser was initially developed, as the package name suggests).
The relevant part of the commit message is:
As you noted, the
.intern()should not be necessary (and should have no visible effect) on a conforming JVM implementation.My guess is that
In the second case I’d expect some note of that in a comment or in the comment message, however.
One side-effect of that
.intern()call is that initializers are no longer constant expressions and the fields will not be inlined by other classes referencing them.That will ensure that the classXMLScanneris loaded and its field read. I don’t think this is relevant here, however.