Proposal: abstract class implementing sealed interface, relaxing the rules

The rules that would need to be enforced for my proposed changes to work may be formalized as follows:

  • let I be a sealed interface defined in package P, in module M;
  • let I' be a set of all the non-sealed interfaces inheriting, either directly or indirectly, from I in the sealed taxonomy of I;
  • a class A defined in package P', in module M', where P' != P or M' != M, is allowed to implement I if and only if criteria(A) holds.

Given a class T, criteria(T) holds if and only if any of the following conditions are true:

  • T implements at least one interface in I';
  • all the following conditions are true at the same time:
    • T is sealed;
    • for each subclass T' of T, criteria(T') holds;
  • all the following conditions are true at the same time:
    • T is abstract;
    • no constructor of T satisfies any of the following conditions:
      • it is more visible than internal;
      • it is annotated with @PublishedApi;
    • for each subclass T' of T, criteria(T') holds.