trying to use reflection in 1.5.0-M2 and somehow t...
# announcements
p
trying to use reflection in 1.5.0-M2 and somehow the get doesn't compile since it expects object of type Nothing and not Transaction:
Copy code
fun getProperties(t: Transaction) {
    t::class.memberProperties.forEach {
            println(it.name)
            println(it.get(t)) // gives error since it doesn't expect type Transaction 
    }
}
y
println((it as KProperty0<Transaction>).get())
p
Thanks, but unfortunately doesn't work. The inferred type is KProperty1<out Transaction, *>
not the best workaround, but what worked:
println(it.javaGetter!!(t))
a
Is that a regression in 1.5-M2? Can you please file a bug at http://kotl.in/issue with a self-contained sample code to reproduce?
y
Try
println((it as KProperty1<Transaction, Any?>).get(t))
then. You could also do a simple
(t::class as KClass<Transaction>).memberProperties.forEach {...}
to solve the problem from its root
p
Sorry, not sure this is a regression issue since I didn't use it before 1.5-M2 (so msot likely just a user error ;). The suggested casts also don't work. To make the issue even more simple and reproducible:
Copy code
class Person(val name:String)
val peter = Person("peter")

peter::class.memberProperties.forEach {
    it.get(peter) // doesn't compile
}
a
Thank you. Yes, this is an old known issue, see https://youtrack.jetbrains.com/issue/KT-16432 discussion.
­čĹŹ 1