kotlin-reflect

What is the purpose of having bound class reference return a covariant type?

你离开我真会死。 提交于 2019-11-29 11:01:28
I'm playing with reflection and I came out with this problem. When using bound class reference via the ::class syntax, I get a covariant KClass type: fun <T> foo(entry: T) { with(entry::class) { this // is instance of KClass<out T> } } As I could learn from the docs, this will return the exact type of the object, in case it is instance of a subtype of T , hence the variance modifier. However this prevents retrieving properties declared in the T class and getting their value (which is what I'm trying to do) fun <T> foo(entry: T) { with(entry::class) { for (prop in memberProperties) { val v =

What is the purpose of having bound class reference return a covariant type?

随声附和 提交于 2019-11-28 04:25:43
问题 I'm playing with reflection and I came out with this problem. When using bound class reference via the ::class syntax, I get a covariant KClass type: fun <T> foo(entry: T) { with(entry::class) { this // is instance of KClass<out T> } } As I could learn from the docs, this will return the exact type of the object, in case it is instance of a subtype of T , hence the variance modifier. However this prevents retrieving properties declared in the T class and getting their value (which is what I'm