我认为只访问members
对象的KClass
字段即可。但是,我找到了一个案例,但事实并非如此。两个测试都抛出异常。
@Test fun mapProperties() {
val map = mapOf("a" to "b")
val cls = map.javaClass.kotlin
cls.members
}
抛出: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
}
抛出:kotlin.reflect.KotlinReflectionInternalError: No metadata found for public abstract val entries: [Not-computed] defined in kotlin.collections.Map[DeserializedPropertyDescriptor@5c1a8622]
不确定我是偶然发现了一个错误还是错过了什么。