In Kotlin, I can obtain a KType
from a KClass<*>
like so:
Int::class.createType()
Kotlin .智力
How do I do the reverse and obtain the KClass<Int>
from a KType
representing a Kotlin .智力
?
In Kotlin, I can obtain a KType
from a KClass<*>
like so:
Int::class.createType()
Kotlin .智力
How do I do the reverse and obtain the KClass<Int>
from a KType
representing a Kotlin .智力
?
You can use KType.classifier
for this:
val intType : KType = Int::class.createType()
val intClassifier : KClassifier? = intType.classifier
assertEquals(Int::class, intClassifier) // true
请注意,由于1.3.40,您还可以(至少在JVM上)使用实验性的typeOf<Int>()
来获得KType
.你可能想看看1.3.40-announcement,看看它是否对你有用.
Speaking of the JVM: on the JVM you can also use KType.jvmErasure
to get the actual class as also marstran pointed out in the comment.