Anonymous classes are not final according to reflection API

John Rose john.r.rose at
Tue Jul 7 03:42:04 UTC 2015

But that's a hack too. It breaks if the name computes to a null string. As opposed to the documented null CP ref. 

– John

> On Jul 3, 2015, at 7:17 AM, Maurizio Cimadamore <maurizio.cimadamore at> wrote:
>> On 02/07/15 23:10, Dan Smith wrote:
>> - The JLS assertion "An anonymous class is always implicitly final" is meaningless if it's not interpreted as "the ACC_FINAL flag on the generated class is set", so if we're not going to enforce that, the assertion should be dropped.  (The other assertions in 15.9.5 have language-level implications, but not this, since none of the corresponding language restrictions in could ever arise.)
> unless the VM, javac, and JDK (reflection) agree on a standard form in which anonymous classes are encoded. It seems like reflection has an 'isAnonymousClass' method, whose implementation does the following:
> public boolean isAnonymousClass() {
>     return "".equals(getSimpleName());
> }
> So we already have a way to establish if a class is anonymous in the runtime. Which means we also have a way to infer correct finality without touching ACC_FINAL.
> Maurizio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the compiler-dev mailing list