Morning guys,
We have an interesting use case of generics in kotlin:
Copy code
import kotlin.reflect.KClass
fun main() {
doSomething(B::class, C::class)
}
fun <T : A> doSomething(vararg dialogClasses: KClass<T>) {
// no-op
}
open class A
class B : A()
class C : A()
the compiler complains about the second argument of
doSomething()
function even if it is a sub-type of
A
. Is there any reason for this complaint?
How can this issue can be solved?
t
ti4n
03/03/2021, 10:18 AM
Copy code
fun doSomething(vararg dialogClasses: KClass<out A>) {
// no-op
}