[sealed] Sealed local classes?

Tagir Valeev amaembo at gmail.com
Fri Oct 11 03:02:49 UTC 2019


Sorry if this was already discussed, but what about enums extending
sealed interfaces? E.g.:

sealed interface X permits Foo {}
enum Foo implements X {  // can we do this?
  A {}, // and what about this? Here we have an additional subclass at
runtime. Or we should explicitly declare "non-sealed enum Foo" to
allow this?

With best regards,
Tagir Valeev.

On Thu, Oct 10, 2019 at 3:46 PM Maurizio Cimadamore
<maurizio.cimadamore at oracle.com> wrote:
> On 10/10/2019 01:50, Brian Goetz wrote:
> > Right. We already restrict anon and lambda instances of the sealed
> > type. Not only can't we stably write down their types in the PS
> > attribute, but even if we could, it's so easy to accidentally lose
> > exhaustiveness.
> This is a very good point; if I have type T = A | B | C, but then I have
> 'anonymous' Ts flying around, all switches assuming A|B|C are no longer
> exhaustive.
> Maurizio

More information about the amber-spec-experts mailing list