Basically that. I'm wondering how to get the functions/methods given a KClass... looks like I can only iterate over the properties and extension properties.
Update: You can now get functions of a class with extensions declared in package kotlin.reflect
: functions
, declaredFunctions
, memberFunctions
, staticFunctions
, etc.
Kotlin reflection is a work in progress at the moment. We plan to ship API for introspecting functions in the next milestone, presumably at the end of this summer.
Meanwhile, the only workaround is to use Java reflection for this task.
Kotlin reflection is more full featured in later milestones include the 1.0 betas.
View the overview documentation for Kotlin Reflection and specifically that of KClass.
For example, given a class you can see member functions using:
val functions = Someclass::class.declaredMemberFunctions
or properties:
val properties = Someclass::class.declaredMemberProperties
And to get from a Java Class to a KClass:
val kclz = this.javaClass.kotlin
See also: Kotlin.reflect package API docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With