I assumed that it's OK to just access members
field of a KClass object. But I have found a case when it's not. Both tests throw exceptions.
@Test fun mapProperties() {
val map = mapOf("a" to "b")
val cls = map.javaClass.kotlin
cls.members
}
Throws: kotlin.reflect.KotlinReflectionInternalError: Incorrect resolution sequence for Java field public open val values: kotlin.collections.MutableCollection<(V..V?)> defined in java.util.Collections.SingletonMap[JavaPropertyDescriptor@10163d6]
@Test fun mapProperties2() {
val map = mapOf("a" to "b")
val cls = clsByReified(map)
cls.members
}
inline fun <reified T: Any> clsByReified(instance: T): KClass<T> {
return T::class
}
Throws: kotlin.reflect.KotlinReflectionInternalError: No metadata found for public abstract val entries: [Not-computed] defined in kotlin.collections.Map[DeserializedPropertyDescriptor@5c1a8622]
Not sure if I stumbled upon a bug or just missing something.
Aucun commentaire:
Enregistrer un commentaire