I'm using the typeclassless style of DI via interface composition.
class G
class H
interface A<T> {
fun T.foo(t: T): T
}
interface B : A<G>
interface C : A<H>
interface E : B, C // Compiler error: Type parameter T of 'A' has inconsistent values: InterfaceComposition.G, InterfaceComposition.H
Is there a way to get around the compiler error?
My use case is that A is a generic handler of events of type T. So B and C are specific handler implementations for the events G and H.
I would like to be able to do:
val a: A = TODO()
when (a) {
is B, is C -> a.foo(..)
else -> TODO()
}
Without a common base interface, I'd have to do:
val a: A = TODO()
when (a) {
is B -> a.foo(..)
is C -> a.foo(..)
else -> TODO()
}
Thanks!