
Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
>> Why does the first if statement return false, and the second return
>> true?
[quoted text clipped - 10 lines]
> object), the second compares them for *equality* (do they have the
> same contents).
OK. I saw in the JIAN book that == does equal value for primitive, and
equal identity for reference. Any way to convert a reference type to a
primitive type so that the == can be used for strings?
We're looking at converting some legacy code to Java, and this would be
more "natural" for us :)
Thanks for the help,
Alex
Gordon Beaton - 26 May 2006 07:56 GMT
> OK. I saw in the JIAN book that == does equal value for primitive, and
> equal identity for reference. Any way to convert a reference type to a
> primitive type so that the == can be used for strings?
>
> We're looking at converting some legacy code to Java, and this would
> be more "natural" for us :)
...but less natural for Java.
At any rate, look into String.intern(). Interned Strings can be
compared using ==, however that requires you to intern() all of the
Strings you encounter. I think you'll find that using equals() is less
trouble, and less error prone.
The topic has often been discussed in comp.lang.java.programmer, where
you'll also discover much more traffic than in this (defunct) group.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e