RFR: 8027470: AnnotationSupport uses == rather than .equals to compare Class objects
joel.franck at oracle.com
Mon Nov 18 07:54:32 UTC 2013
On 2013-11-16, Remi Forax wrote:
> 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 220.127.116.11 says that synchronized on a static method is equivalent to
> so == is fine.
Also the VM spec $5.3 notes that
"A well-behaved class loader should maintain three properties:
Given the same name, a good class loader should always return the
same Class object."
(Granted "the same" might not be formal, and this is a recommendation.)
More information about the core-libs-dev