RFR: JDK-8315458 Implement JEP 463: Implicitly Declared Classes and Instance Main Method (Second Preview) [v19]
Joe Darcy
darcy at openjdk.org
Tue Nov 21 14:43:26 UTC 2023
On Tue, 21 Nov 2023 10:38:36 GMT, Pavel Rappo <prappo at openjdk.org> wrote:
>> Look at the spec https://bugs.openjdk.org/browse/JDK-8319252 under 7.3 Compilation Units.
>>
>> - It is not abstract (8.1.1.1 ⇗).
>> - It is final (8.1.1.2 ⇗).
>> - It is a member of an unnamed package (7.4.2 ⇗) and **has package access**. Its direct superclass is Object (8.1.4 ⇗).
>> - It does not have any direct superinterfaces (8.1.5 ⇗).
>> - The body of the class contains every ClassMemberDeclaration (these are declarations of fields (8.3 ⇗), methods (8.4 ⇗), member classes (8.5 ⇗), and member interfaces (9.1.1.3 ⇗)) from the simple compilation unit. It is not possible for a simple compilation unit to declare an instance initializer (8.6 ⇗), static initializer (8.7 ⇗), or constructor (8.8 ⇗).
>> -It has an implicitly declared default constructor (8.8.9 ⇗).
>
> @JimLaskey, in my experiments for JDK-8308715 (Create a mechanism for Implicitly Declared Class javadoc), I found that `javax.lang.model.util.Elements.getOrigin` reports `Origin.EXPLICIT` for the implicitly declared class and `Origin.MANDATED` for that class' constructor. Shouldn't they both be `Origin.MANDATED` because the elements are created from source, not class files, which have some limitations on `ACC_MANDATED`?
> @pavelrappo Classes can’t be MANDATED. Looking at the code I see that EXPLICIT is the default return value when no other conditions apply.
While it is true that the class file format cannot capture MANDATED status for classes, that doesn't necessarily imply mandated-ness shouldn't be track for classes created from sources while inside javac.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/16461#issuecomment-1821055805
More information about the compiler-dev
mailing list