Class modifiers in Java 16

Remi Forax forax at univ-mlv.fr
Thu May 27 13:32:48 UTC 2021


----- 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