Possible refinement for sealed classes
Guy Steele
guy.steele at oracle.com
Thu Apr 1 15:30:31 UTC 2021
> On Apr 1, 2021, at 9:23 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
>
> ...
> Without trying to paint the bikeshed, this is a pretty simple extension to sealing:
>
> sealed interface WithCheese __refines Sandwich { }
>
> This says that WithCheese is sealed to either classes that extend Sandwich, or other interfaces that __refines Sandwich. As a bonus, default methods in WithCheese can refer to methods in Sandwich, since it must always be the case that `this instanceof Sandwich`.
>
> Essentially, I want to put the `permits` list on Sandwich, and have `WithCheese` and friends delegate their permits to `Sandwich`, rather than having each interface enumerate their subtypes.
Maybe “__refines” should be spelled “extend”?
If an interface J extends a class C, it means that it is a compile-time error if class D implements interface J but class D is not a subclass of C.
Such a constraint might be useful even if C is not sealed.
—Guy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20210401/21b6f105/attachment.htm>
More information about the amber-spec-experts
mailing list