[sealed] Sealed local classes?

Brian Goetz brian.goetz at oracle.com
Thu Oct 10 00:50:30 UTC 2019

> In your other email I guess you are referring to anonymous classes 
> implementing a sealed interface, right? E.g.
> sealed interface Foo {
>     void m();
>     /* static final */ Foo f1 = new Foo() { ... }
>     /* static final */ Foo f2 = () -> {};
> }

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 

> (*) there's also a technical reason as to why inferring permitted 
> types based on things inside field initializers and method bodies is 
> not sound: again it has to do with annotation processing. Presumably 
> you want all your inference completed before annotation processors are 
> run. But, by design, annotation processor only requires declarations 
> to be processed, not entire method bodies. So it would not be 
> possible, under the current regime at least, to gather up all 
> permitted types inside all method bodies _before_ annotation processing.


More information about the amber-spec-experts mailing list