classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] Small java.util.Locale change


From: Robert Schuster
Subject: Re: [cp-patches] Small java.util.Locale change
Date: Mon, 20 Dec 2004 03:18:51 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.7.3) Gecko/20040930



Andrew John Hughes wrote:

I spotted a small bug in java.util.Locale while trying to debug a problem in
java.util.Currency.  The equals method compares String objects using ==
rather than equals().
    Locale l = (Locale) obj;

-    return (language == l.language
-            && country == l.country
-            && variant == l.variant);
+    return ((language.equals(l.language))
+            && country.equals(l.country)
+            && variant.equals(l.variant));
  }

I am not sure whether this is needed. I have seen that the constructors of Locale call intern() on the String instances given as arguments. The Strings which exists at compile time are automatically intern()'ed. That means referential equality should work in equals().

The docs of String.intern() describe this magic a little better. :-)

cu
Robert





reply via email to

[Prev in Thread] Current Thread [Next in Thread]