wrongwrong
08/16/2021, 8:06 PMKFunction without kotlin-reflect (using kotlinx-metadata-jvm), but I couldn't get Metadata with valid information, so I have a question.
What I want to achieve is as follows.
1. get the information of arguments and return values from KFunction.
2. get javaConstructor or javaMethod from KFunction.wrongwrong
08/16/2021, 8:08 PMMetadata annotation can be retrieved from a KFunction, the contents are almost empty.
package org.example
import kotlin.reflect.KFunction
data class DataClass(val value: String)
fun main() {
val function: KFunction<*> = ::DataClass
val metadata: Metadata = function::class.java.getAnnotation(Metadata::class.java)!!
println(metadata.data1.asList()) // -> []
println(metadata.data2.asList()) // -> []
}
On the other hand, looking at the bytecode of the synthetic class generated as a FunctionReference, it looks like there is a valid Metadata.
How can I get this Metadata?wrongwrong
08/16/2021, 8:09 PMKFunction without using kotlin-reflect, I would be grateful if you could let me know.
Thank you.wrongwrong
08/21/2021, 9:13 AMKFunction retrieved as Reference can be cast to kotlin.jvm.internal.FunctionReference, so various information could be read from it.
From (functionReference.owner as ClassBasedDeclarationContainer).jClass, we could also read information about the Class from which it was defined.