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 packageP
, in moduleM
; - let
I'
be a set of all the non-sealed interfaces inheriting, either directly or indirectly, fromI
in the sealed taxonomy ofI
; - a class
A
defined in packageP'
, in moduleM'
, whereP'
!=P
orM'
!=M
, is allowed to implementI
if and only ifcriteria(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 inI'
; - all the following conditions are true at the same time:
-
T
is sealed; - for each subclass
T'
ofT
,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
;
- it is more visible than
- for each subclass
T'
ofT
,criteria(T')
holds.
-