Melvin Biamont
02/21/2021, 6:06 PMtypealias AFunction<R, A> = suspend (args: A) -> Result<R>
val functionMap = mutableMapOf<String, AFunction<Any?, Any?>>()
fun <R, A> addFunctionToMap(name: String, function: AFunction<R, A>) {
functionMap[name] = function
}
For some reasons, it doesn’t compile (on the line functionMap[name] = function
) as it is saying it was expecting a type AFunction<Any?, Any?>
and not AFunction<R, A>
.
I tried modifying a bit the addFunctionToMap
function like this:
fun <R: Any?, A: Any?> addFunctionToMap(name: String, function: AFunction<R, A>) {
functionMap[name] = function
}
But, it doesn’t change the compiler error.
Do you have an idea how I could solve that?
🙏Timo Gruen
02/21/2021, 6:25 PMRuckus
02/21/2021, 7:06 PMMutableMap<String, AFunction<*, *>>
Melvin Biamont
02/21/2021, 7:27 PMMutableMap<String, AFunction<*, *>>
works .. but
Then if I try to call the function in it, the compiler tells me the parameter is of type Nothing
(because of the Star projection).Ruckus
02/21/2021, 7:42 PMMatteo Mirk
02/22/2021, 2:22 PM