abstract 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?
y
Youssef Shoaib [MOD]
05/03/2024, 5:39 AM
Change it to
KClass<out Base>
r
Ray Rahke
05/03/2024, 5:42 AM
what does out mean?
Ray Rahke
05/03/2024, 5:43 AM
also is there a way for me to create an alias to not have to type
KClass<out Base>
all the time
Ray Rahke
05/03/2024, 5:43 AM
can I do like
Copy code
type Cls<T> = KClass<out T>
y
Youssef Shoaib [MOD]
05/03/2024, 6:23 AM
Yeah you can do that with
typealias
. 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