I am trying to read the annotations of a value that I pass to a function. I have an annotation defined as:
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.EXPRESSION)
annotation class MyAnnotation
The annotation is given to an expression, such as:
public main() {
val myValue: Int = @MyAnnotation 1001
printAnnotationNames(myValue)
}
How would I be able to read the annotations of obj
instance at runtime?
fun printAnnotationNames(obj: Any) {
// ... ?
}
It cannot be done by its class type.