Anonymous classes are not final according to reflection API

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Jul 3 14:17:34 UTC 2015



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 8.1.1.2 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 booleanisAnonymousClass() {
     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: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20150703/291f12ed/attachment.html>


More information about the compiler-dev mailing list