[statics] allowing static initializers in interfaces?

Remi Forax forax at univ-mlv.fr
Tue Nov 17 14:15:42 UTC 2020


----- Mail original -----
> De: "Maurizio Cimadamore" <maurizio.cimadamore at oracle.com>
> À: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Mardi 17 Novembre 2020 15:03:39
> Objet: [statics] allowing static initializers in interfaces?

> Hi,
> now that the work on allowing static members in nested declarations [1]
> is wrapping up, I'm wondering if we could add treatment for one more
> case: static initializers in interfaces. This seems a case where the
> static compiler is already inserting static blocks (to initialize any
> static fields an interface might declare), but where the JLS is
> currently forbidding interfaces from having an explicit static
> initializer block in the source code. This make e.g. initialization of
> fields which might throw exceptions (e.g. method handles) not possible
> inside interfaces. While I realize this is a corner case, I thought it
> would still be worth asking the question :-)

+1 for me,

Yes, it's time of heal the rift between a class and an interface, we stop halfway by just adding default methods and later private methods.

So currently, there are 3 ad_hoc differences
- as you said, no static block, even if you can initialize a static field with an initializer
- no private class
- no private static field.

The last will also requires a change of the JVM spec.

> 
> Cheers
> Maurizio

cheers,
Rémi

> 
> [1] - https://git.openjdk.java.net/jdk/pull/571


More information about the amber-spec-experts mailing list