How to get parameter names through reflection in Kotlin?
Update : The Reflection API now supports getting parameter names: it KCallable.parameters
will give you a list of parameters, but it KParameter.name
will give you a name.
The current solution is to use annotation JetValueParameter
, although it is deprecated.
We are working on support for parameter names in Kotlin reflection, which will be available soon. At this point, it JetValueParameter
will be dropped in favor of the new API.
I would like to point out that the Kotlin compiler currently only generates Java 1.6 compliant JVM bytecode, while the javac MethodParameters
compliant attribute -parameters
only appeared in Java 1.8 bytecode. So you still won't be able to get the parameter names of Kotlin methods using Java reflection. We are considering support for 1.8 bytecode, although this will likely work in the future.
source to share