给出注释
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class MyAnnotation
如何使用此注释查找方法?
这是我走了多远:
val cls = myObject.javaClass.kotlin
val found = cls.memberFunctions.filter { it.annotations.contains( ??? ) }
答案 0 :(得分:7)
注释将是您的MyAnnotation
课程的实例。因此,您需要做的就是:
cls.memberFunctions.filter { it.annotations.any { anno -> anno is MyAnnotation } }