2016-06-02 3 views
3

은 주석 클래스에서 주석이있는 메소드를 찾는 방법은 무엇입니까?

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

방법이 주석과 방법을 찾을 수

을 감안할 때?

이것은 내가 가지고 얼마나 멀리입니다 :

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

답변

7

주석은 MyAnnotation 클래스의 인스턴스가 될 것입니다. 따라서 다음을 수행하면됩니다.

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