Brock Weaver wrote:
> Java has turned out to be a very successful language. Some may argue it is
> not a "good" language as it makes certain compromises ("joe" == "joe"
> returns false -- now that seems weird, albeit correct since there is no
> operator overloading).
Not so, actually. All Java string constants and compile-time expressions
are put in the intern pool, so "joe" and "joe" will always test ==,
because they are guaranteed to be the same object. "joe" will not
necessarily test == to a String object with a value of "joe", but it is
guaranteed to if you have used the intern() method.
public final class Joe {
public static void main (String[] args) {
System.out.println ("joe" == "joe"); // true
final String joe = "joex".substring(0, 3);
System.out.println (joe == "joe"); // false
final String joe2 = joe.intern ();
System.out.println (joe2 == "joe"); // true
System.exit (0);
}
}
--
John W. Kennedy
"Information is light. Information, in itself, about anything, is light."
-- Tom Stoppard. "Night and Day"