Sealed local interfaces
Remi Forax
forax at univ-mlv.fr
Mon Aug 17 14:07:23 UTC 2020
I've found a discrepancies in the current spec of sealed,
the current spec allows local sealed interface but you have no way to provide a sub-types apart a sealed sub interfaces.
A record or an interface is allowed to be declared inside a method,
by example, this is a valid code
static void foo() {
interface I {}
record Foo() implements I {}
}
the interface can also be sealed
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 rule was intended to not allow this kind of code
sealed interface I {}
static void foo() {
record Foo implements I {}
}
because the interface I is visible while Foo is not.
But we have forgotten to discuss about the case where both Foo and I are in the same scope.
I see two possible fixes
- disallow sealed local interfaces
- allow local class/record to implement a sealed interface if they are in the same scope.
Rémi
More information about the amber-spec-experts
mailing list