I’m struggling understanding how to use in/out for generic types, here is what I’m trying to do :
interface Executor<T, U> {
fun isExecutable(): (T) -> Boolean
fun execute(): suspend (U) -> Unit
}
class MyClass<T, U> {
val executors = mutableMapOf<String, Executor<T, U>>()
fun register(eventName: String, executor: Executor<T, U>) {
executors[eventName] = executor
}
inline fun <reified V : U> register(executor: Executor<T, V>) {
val eventName = V::class.toString()
register(eventName, executor)
}
}
I get the following error from the IDE
Type mismatch. Required: Executor<T, U>, Found: Executor<T, V>
U
is a sealed class and
V
a subtype of that class. I did read the page about generic and “PECS” in the doc, but I still haven’t figured it out. Anyone knows what I need to change?