Refinements for sealed types

Brian Goetz brian.goetz at
Mon Aug 19 18:52:16 UTC 2019

>>> How do you know from `sealed class X {}` and the rest of its 
>>> compilation unit that all X's subtypes are co-declared? 
>> By co-declared, I mean "in the same compilation unit."
> The emphasis should be on the word "all", not "co-declared". How do 
> you know that ALL of X's subtypes are declared in the same compilation 
> unit?

Here's what I'm suggesting.

If you say

     sealed interface X { ... }

with no permits clause, then the permits clause is inferred from the 
contents of the compilation unit, which is _by definition_ all the 
permitted subtypes.  (If there are no subtypes in the current 
compilation unit, a warning may be in order.)

Similarly, if you have a subtype of X:

     sealed interface X {
         class A implements X { }

that is _in the same compilation unit_, then we will infer `sealed` on A 
unless you say otherwise.

In all other cases, subtypes of sealed types must either say "sealed" or 
"non-sealed" (or "final").

More information about the amber-spec-experts mailing list