Richard -

This behavior you are seeing is due to Java's "intern()"ing of Strings. See
the Lang Spec for more details.

In Java, all String constants are stored in a global table. So any constants
with the same value are really the same object, as demonstraited by your
code below.

- Paul Philion

----- Original Message -----
From: Richard Clark <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, January 06, 2000 1:50 PM
Subject: Re: Checking for null


> Thanks for the corrections -- somewhere along the line I had picked up the
> mistaken notion that Java treated "==" and ".equals" as the same thing
> (which always puzzled me as it went against my understanding of languages
> that used references.) A quick check of the language specification cleared
> that up.
>
> An interesting side note:
>   String a = "Hello"; String b = "Hello"; // or even String b = "H" +
"ello"
>   if (a == b) System.out.println("a == b");
>   if (a.equals(b)) System.out.println("a.equals(b)");
>
> prints both "a == b" and "a.equals(b)" using both the Sun JDK 1.2 compiler
> and jikes on Windows NT. This is part of what led me astray so long ago,
and
> I re-ran the experiment today with the same result.
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to