Ray Rahke
05/03/2024, 5:35 AMabstract class Base {}
class Sub : Base() {}
abstract class Foo {
abstract val x: KClass<Base>
}
class Bar: Foo {
override val x: KClass<Base> = Sub::class
/*
Type mismatch.
Required: KClass<Base>
Found: KClass<Sub>
*/
}
How to fix?Youssef Shoaib [MOD]
05/03/2024, 5:39 AMKClass<out Base>
Ray Rahke
05/03/2024, 5:42 AMRay Rahke
05/03/2024, 5:43 AMKClass<out Base>
all the timeRay Rahke
05/03/2024, 5:43 AMtype Cls<T> = KClass<out T>
Youssef Shoaib [MOD]
05/03/2024, 6:23 AMtypealias
. The issue here btw is that KClass is invariant, but you want to use it similar to how a list is used, as in that it should "output" things of type Base
, hence the out
projected type