ato*_*tok 3 java reflection kotlin
给出一个注释
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class MyAnnotation
Run Code Online (Sandbox Code Playgroud)
如何使用此注释查找方法?
这是我得到了多远:
val cls = myObject.javaClass.kotlin
val found = cls.memberFunctions.filter { it.annotations.contains( ??? ) }
Run Code Online (Sandbox Code Playgroud)
注释将是您的MyAnnotation类的实例.因此,您需要做的就是:
cls.memberFunctions.filter { it.annotations.any { anno -> anno is MyAnnotation } }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
656 次 |
| 最近记录: |