[sealed] Sealed local classes?

Brian Goetz brian.goetz at oracle.com
Wed Oct 9 21:26:26 UTC 2019


It is allowable, though somewhat silly, to put the `final` modifier on 
local classes.

 From a hierarchy-protection point of view, allowing local classes to be 
`sealed` is also silly, as it cannot be extended from outside the method 
anyway, and even if it could, such types can't show up in APIs that are 
accessible from outside.

 From an exhaustiveness point of view, though, one can imagine having a 
sealed local hierarchy (sum of records) that will be switched over 
within the method, though one would have to work pretty hard to imagine 
that.

Note that a local class cannot be a subtype of a sealed type declared 
outside the same method (*), since it can't be denoted in the permits 
clause.

(*) unless the permits clause is inferred.  Yuck.  Now a mangled name 
would go into the PermittedSubtypes attribute.

Proposal: ban `sealed` and `non-sealed` modifiers on _local_ classes and 
interfaces.


More information about the amber-spec-experts mailing list