exbuddha
exbuddha

Reputation: 633

how do I get annotation instances that are declared by AnnotationTarget.EXPRESSION?

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.

Upvotes: 0

Views: 18

Answers (0)

Related Questions