Hey Kotlin community. Could anyone help me underst...
# announcements
g
Hey Kotlin community. Could anyone help me understand why
x::class
produces
KClass<out T>
instead of just
KClass<T>
in the following snippet?
Copy code
class Test<T : Any>(val x: T) {
  fun type(): KClass<T> = x::class // doesn't compile bc types don't match!
}
And a follow-up question, is there any way to make this compile without having to cast the result of
x::class
to
KClass<T>
?
d
It is because x can be any type that is T or inherits T.