Question re: JEP 492 specification

Archie Cobbs archie.cobbs at gmail.com
Tue Dec 10 21:56:42 UTC 2024


The proposed JLS changes for JEP 492 are saying that this example should no
longer compile*:

    static {
        class Local1 {
            class Local2 {
                public static void m() {
                    new Local1();  // error
                }
            }
        }
    }

but that seems wrong - that exampple has been allowed since JDK-8254321,
and as it has nothing to do with flexible constructors, it should continue
to be allowed.

The JEP 492 spec says (new additions in bold):

  If *C* is an inner local class, then:

   -

   If *C* occurs in a static context, then *i* has no immediately enclosing
   instance. *Let S be the nearest static method declaration, static field
   declaration, or static initializer that encloses the declaration of C. If
   the nearest static method declaration, static field declaration, or static
   initializer that encloses the class instance creation expression is not S,
   then a compile-time error occurs.*

Should there be an *Otherwise* at the beginning of the newly added
sentence? (And same thing in the previous paragraph regarding anonymous
classes)

-Archie

* See JDK-8345953 <https://bugs.openjdk.org/browse/JDK-8345953> JEP 492:
instantiating local classes in a different static context should not be
allowed

-- 
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-experts/attachments/20241210/57f29613/attachment.htm>


More information about the amber-spec-experts mailing list