RFR: 8027470: AnnotationSupport uses == rather than .equals to compare Class objects
forax at univ-mlv.fr
Sat Nov 16 10:21:08 UTC 2013
On 11/15/2013 04:21 AM, Joseph Darcy wrote:
> Catching up on email, the specification of java.lang.Class does not
> explicitly promise that its notion of equality must be identity for
> all time. Therefore, while not required for today's implementations, I
> would prefer that new code we write in the JDK use equals rather than
> == when comparing classes.
The JLS requires implicitly that Class object are interned.
JLS7 126.96.36.199 says that synchronized on a static method is equivalent to
so == is fine.
> On 10/31/2013 3:24 AM, David Holmes wrote:
>> Hi Andreas,
>> On 31/10/2013 7:49 PM, Andreas Lundblad wrote:
>>> Please review the fix for JDK-8027470 below.
>>> AnnotationSupport compared Class-instances using '==' where it
>>> should be using '.equals'. Fixed in this patch.
>> Class is final and does not override Object.equals therefore it is
>> guaranteed to be based on identity. This change, while harmless, is
>> unnecessary. Comparison of Class instances with == occurs throughout
>> the JDK.
>>> Link to web review:
>>> Link to bug reports:
>>> -- Andreas Lundblad
More information about the core-libs-dev