查找与注释匹配的特定 class 的方法

Find the methods of a particular class matching an annotation

我有两个注释,我们称它们为@Foo 和@Bar。 @Foo 是 class (又名类型)级注释,@Bar 是方法级注释。我的意图是针对给定的@Foo class,遍历所有@Bar 方法。最合适的方法是什么?目前,我正在为 Java 使用 Google Reflections API。

谢谢。

Wero 的评论有效: "you can simply use fooClass.getDeclaredMethods() to enumerate the (declared) methods and method.getAnnotation(Bar.class) != null to filter for the bar methods"