Class modifiers in Java 16
forax at univ-mlv.fr
forax at univ-mlv.fr
Mon May 31 12:13:30 UTC 2021
----- Mail original -----
> De: "Tagir Valeev" <amaembo at gmail.com>
> À: "Brian Goetz" <brian.goetz at oracle.com>
> Cc: "Remi Forax" <forax at univ-mlv.fr>, "compiler-dev" <compiler-dev at openjdk.java.net>, "amber-dev"
> <amber-dev at openjdk.java.net>
> Envoyé: Dimanche 30 Mai 2021 06:48:13
> Objet: Re: Class modifiers in Java 16
> Thank you for the answers. Judging from the javac behavior, 'static'
> modifier on local classes is still not allowed, so the sentence 8.1.1
> is wrong, as for Java 16.
yes, using static explicitly is not yet allowed.
Enums, records and interfaces which are implicitly static are all allowed.
And as i said earlier, for a reason ?, annotations are not allowed despite being implicitly static.
>
> What about my second question, access modifiers? Is this intended
> change to allow them inside local/anonymous classes?
Local classes/anonymous classes should not have access modifiers, they are scoped inside the method they are defined, so no modifier is needed.
>
> With best regards,
> Tagir Valeev.
regards,
Rémi
>
> On Thu, May 27, 2021 at 8:37 PM Brian Goetz <brian.goetz at oracle.com> wrote:
>>
>> I think there’s a bit of preparing for the future here. There’s the concepts
>> (how static interacts with nesting) which is separate from which exact
>> combinations of those concepts that the language currently supports. We’re
>> moving towards trying to get rid of the arbitrary nest-x-in-y rules, step 1 was
>> defining the concepts separate from the arbitrary restrictions, but we haven’t
>> lifted the restrictions yet.
>>
>> On May 27, 2021, at 9:32 AM, Remi Forax <forax at univ-mlv.fr> wrote:
>>
>> ----- Mail original -----
>>
>> De: "Tagir Valeev" <amaembo at gmail.com>
>> À: "compiler-dev" <compiler-dev at openjdk.java.net>, "amber-dev"
>> <amber-dev at openjdk.java.net>
>> Envoyé: Jeudi 27 Mai 2021 12:22:48
>> Objet: Class modifiers in Java 16
>>
>>
>> Hello!
>>
>> I want to clarify my understanding of Java 16 spec and the
>> corresponding compiler behavior regarding class modifiers (8.1.1)
>>
>> 1. static modifier
>> Java 15 spec 8.1.1 [1] says:
>> The modifier static pertains only to member classes (§8.5.1), not to
>> top level or local or anonymous classes.
>>
>> Java 16 spec 8.1.1 [2] says:
>> The modifier static pertains only to member classes and local classes.
>> However, Java 16 spec 14.3 says:
>> It is a compile-time error if a local class or interface declaration
>> has the modifier static (§8.1.1).
>>
>> Is it my bad understanding of English or there's some contradiction?
>> To me, 8.1.1 says that now, local classes can be declared as static
>> while 14.3 says the opposite thing.
>>
>>
>> In JEP 395, under "Static members of inner classes"
>> "We relax this restriction in order to allow an inner class to declare members
>> that are either explicitly or implicitly static. In particular, this allows an
>> inner class to declare a static member that is a record class."
>> that why 8.1.1 was modified.
>>
>> Yes, the sentence in 14.3 seems wrong.
>>
>> Thank you in advance,
>> With best regards,
>> Tagir Valeev.
>>
>>
>> regards,
>> Rémi
>>
>>
>> [1]
>> https://docs.oracle.com/javase/specs/jls/se15/html/jls-8.html#jls-ClassModifier
>> [2]
>> https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ClassModifier
>> [3] https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-14.3
>>
More information about the amber-dev
mailing list