[statics] allowing static initializers in interfaces?

Kasper Nielsen kasperni at gmail.com
Tue Nov 17 16:21:50 UTC 2020


This leaves annotations as the odd one out of top-level classes. Are there any
good reasons for making it a special case?

/Kasper


/Kasper

On Tue, 17 Nov 2020 at 14:10, Brian Goetz <brian.goetz at oracle.com> wrote:
>
> The goal of this effort is to make nesting of static members more
> uniform by eliminating such "gratuitous" restrictions, so this seems
> within the spirit.
>
> On 11/17/2020 9:03 AM, Maurizio Cimadamore wrote:
> > 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 :-)
> >
> > Cheers
> > Maurizio
> >
> > [1] - https://git.openjdk.java.net/jdk/pull/571
> >
>


More information about the amber-spec-observers mailing list