如何在类中找到带注释的方法?

给出一个注释

@Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.RUNTIME) annotation class MyAnnotation 

如何找到这个注释的方法?

这是我得到了多少:

 val cls = myObject.javaClass.kotlin val found = cls.memberFunctions.filter { it.annotations.contains( ??? ) } 

注释将是MyAnnotation类的实例。 因此,你需要做的是:

 cls.memberFunctions.filter { it.annotations.any { anno -> anno is MyAnnotation } }