nanodeath
09/22/2020, 5:00 AMfoo::class
return KClass<out String>
instead of KClass<String>
, and...what are my options if I actually want the latter?nanodeath
09/22/2020, 5:14 AMdiesieben07
09/22/2020, 7:13 AMfoo
. It might be a subtype of the static type (val foo: A = B()
where class B : A()
) - In case of String
that is not possible, but the compiler cannot rely on that (someone might make it open
at some point and then you have a problem with separate compilation).
If you want KClass<String>
use String::class
or something like this.nanodeath
09/22/2020, 3:28 PMnanodeath
09/22/2020, 3:31 PMfun <T : Component> addComponent(c: T) {
I need some way to guarantee that c
is exactly a type T, and not simply a subclass of T. but I don't think there's a way to do that.diesieben07
09/22/2020, 3:34 PMdiesieben07
09/22/2020, 3:35 PMA
extends B
then it must be okay to pass a A
everywhere that expects a B
, otherwise A
should not extend B
.nanodeath
09/22/2020, 4:07 PMnanodeath
09/22/2020, 4:08 PMaddComponent
calls uses T
in both in and out positions though, so...diesieben07
09/22/2020, 4:13 PMnanodeath
09/22/2020, 4:47 PM