https://kotlinlang.org logo
#reflect
Title
# reflect
t

TwoClocks

04/16/2021, 6:02 PM
anyone know how to compare a KType to a actual type? I want to say something like
if( someProp.returnType == Double::class )
In this case I could create an instance of a
Double
and get it's type... but pretend the type is of a class that it's not easy/possible to get an instance of easily.
d

diesieben07

04/16/2021, 6:34 PM
KType.classifier
will give you the "raw type" (either
KClass
or
KTypeParameter
) which you can then compare to e.g.
Double::class
t

TwoClocks

04/16/2021, 6:38 PM
Oooo! classifiers. a new concept to me... I'll read up. But yeah, that compare totally works in my code. Thanks!
165 Views