最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

kotlin - how do I get annotation instances that are declared by AnnotationTarget.EXPRESSION? - Stack Overflow

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论