y
10/16/2023, 10:14 AMsealed interface MyInterface
where every implementor is MySealedClass()
(why? because MySealedClass
is a huge class and I need a subset of the subclasses). is there any way to make Kotlin understand this property?
the best I can think of is to give the interface an infallible fun toMySealedClass(): MySealedClass = when (this) { is MySealedClass -> this }
function which statically validates this property, but ideally I'd like not having to keep using it every time I have something that is MyInterface
and instead have Kotlin understand that it's a MySealedClass
.Youssef Shoaib [MOD]
10/16/2023, 11:18 AMy
10/16/2023, 11:26 AMMySealedClass
is a major, already-existing class. it is unlikely that I'll be allowed to significantly change it.Loney Chou
10/17/2023, 7:20 AMMyInterface
and automatically cast that into MySealedClass
, but it may also break the code too bad if even later another subtype for MyInterface
is needed, as known as "extensibility hurts".y
10/17/2023, 7:29 AM