Details
-
Bug
-
Resolution: Fixed
-
P4
-
7, 8
Description
"An anonymous class is always implicitly final (§8.1.1.2)."
Longstanding behavior of javac, since 1.3, has been, for the most part, *not* to treat the classes as 'final'. To address this inconsistency, the specification should be changed to accurately reflect the reference implementation.
Specifically, anonymous classes are almost never generated with the ACC_FINAL flag set. We can't change this longstanding behavior without impacting some serialization clients (this would be permissible, but is unnecessarily disruptive). And we can't faithfully implement Class.getModifers (which promises to provide the "Java language modifiers") without the class files encoding the language's modifiers.
Some history:
-
-
-
-
The change impacts the set of legal programs, in that it allows some casts that would be considered illegal under the current specification (see
Attachments
Issue Links
- relates to
-
JDK-8161013 Never treat anonymous classes as 'final'
- Closed
-
JDK-8162946 Casting 'this' from anonymous class to arbitrary interface succeeds
- Resolved
-
JDK-8129576 Anonymous classes are not final according to reflection API
- Resolved
-
JDK-6520152 ACC_FINAL flag for anonymous classes shouldn't be set
- Closed
-
JDK-6219964 Compiler allows illegal cast of anonymous inner class
- Closed
-
JDK-4243945 javac of Kestrel-F produces incompatible anonymous classes
- Closed
-
JDK-4777101 final treatment of anonymous classes not marked in .class files?
- Resolved