julian
06/22/2020, 7:09 PMclass 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!kioba
06/22/2020, 10:30 PMval a: A<T>
, the foo function could be called as long as T
is in receiver scope. ie:
val t: T = TODO()
with(t) { a.foo() }
kioba
06/22/2020, 10:33 PMKroppeb
06/28/2020, 9:30 AMjulian
06/28/2020, 2:16 PMjulian
06/28/2020, 2:17 PM