-
Bug
-
Resolution: Not an Issue
-
P5
-
None
-
7u51, 8u60, 9
if I understand correctly according to following assertion from JLS 15.9.5 anonymous classes are always final:
An anonymous class is always implicitly final (§8.1.1.2).
But reflection API reports that the class is not final. Namely let's consider following code:
import java.lang.reflect.Modifier;
public class Test12 {
static class Foo<T> {}
public static void main(String argv[]) {
Foo<Integer> foo = new Foo<>() {};
if ( (foo.getClass().getModifiers() & Modifier.FINAL) != 0 ) {
System.out.println("final, modifiers: " + foo.getClass().getModifiers());
} else {
System.out.println("not final, modifiers: " + foo.getClass().getModifiers());
}
}
}
On JDK9b69 it reports:
not final, modifiers: 0
javap reports:
final class Test12$1 extends Test12$Foo<java.lang.Integer>
minor version: 0
major version: 52
flags: ACC_FINAL, ACC_SUPER
This seems to be a discrepancy between spec and javac (VM? reflection API?) which should be fixed.
An anonymous class is always implicitly final (§8.1.1.2).
But reflection API reports that the class is not final. Namely let's consider following code:
import java.lang.reflect.Modifier;
public class Test12 {
static class Foo<T> {}
public static void main(String argv[]) {
Foo<Integer> foo = new Foo<>() {};
if ( (foo.getClass().getModifiers() & Modifier.FINAL) != 0 ) {
System.out.println("final, modifiers: " + foo.getClass().getModifiers());
} else {
System.out.println("not final, modifiers: " + foo.getClass().getModifiers());
}
}
}
On JDK9b69 it reports:
not final, modifiers: 0
javap reports:
final class Test12$1 extends Test12$Foo<java.lang.Integer>
minor version: 0
major version: 52
flags: ACC_FINAL, ACC_SUPER
This seems to be a discrepancy between spec and javac (VM? reflection API?) which should be fixed.
- is blocked by
-
JDK-8159751 ObjectStreamClass: hide 'final' flag for anonymous classes
- Closed
- relates to
-
JDK-6520152 ACC_FINAL flag for anonymous classes shouldn't be set
- Closed
-
JDK-8161009 15.9.5: Anonymous classes aren't actually 'final'
- Closed
-
JDK-8160200 4.7.6: Acknowledge that ACC_FINAL may be implicit
- Closed
-
JDK-4777101 final treatment of anonymous classes not marked in .class files?
- Closed