The rules that would need to be enforced for my proposed changes to work may be formalized as follows:
- let
Ibe a sealed interface defined in packageP, in moduleM; - let
I'be a set of all the non-sealed interfaces inheriting, either directly or indirectly, fromIin the sealed taxonomy ofI; - a class
Adefined in packageP', in moduleM', whereP'!=PorM'!=M, is allowed to implementIif and only ifcriteria(A)holds.
Given a class T, criteria(T) holds if and only if any of the following conditions are true:
-
Timplements at least one interface inI'; - all the following conditions are true at the same time:
-
Tis sealed; - for each subclass
T'ofT,criteria(T')holds;
-
- all the following conditions are true at the same time:
-
Tis abstract; - no constructor of
Tsatisfies any of the following conditions:- it is more visible than
internal; - it is annotated with
@PublishedApi;
- it is more visible than
- for each subclass
T'ofT,criteria(T')holds.
-