> On Aug 17, 2020, at 8:07 AM, Remi Forax <fo...@univ-mlv.fr> wrote:
> 
>  static void foo() {
>    sealed interface I {}
> 
>    record Foo implements I {}
>  }
> 
> but this code does not compile because Foo is a local class and a local class 
> can not implement a sealed interface.

This scenario is not directly covered by the specs, because local interfaces 
are a feature of the Records JEP, while 'sealed' is a feature of the Sealed 
Classes JEP. (If we'd noticed the interaction, we could have specified Sealed 
Classes in terms of the "Local Static Interfaces and Enum Classes" changes. But 
if those changes are finalized in 16, the point will be moot.)

However, we *did* make a deliberate choice that a local *class* cannot be 
'sealed' at all, and that restriction should naturally apply to local 
interfaces, too:

"It is a compile-time error if a local class declaration contains any of the 
access modifiers public, protected, or private (6.6), or any of the modifiers 
static (8.1.1), sealed or non-sealed (8.1.1.2)."

I kind of think this is overly-restrictive, but it was a safe way to sidestep 
all the questions that arise due to classes being "unavailable" from a certain 
scope. I think it's worth thinking more carefully about this in the next 
iteration.

Reply via email to