我有一个方法的简单标记注释(类似于Effective Java(第2版)第35项中的第一个例子):
/**
* Marker annotation for methods that are called from installer's
* validation scripts etc.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface InstallerMethod {
}
Run Code Online (Sandbox Code Playgroud)
然后,在一个给定的包(比如说com.acme.installer)中,它有几个包含20个类的子包,我想找到所有用它注释的方法.(因为我想对单元测试中所有带注释的方法进行一些检查.)
什么(如果有的话)是最简单的方法呢?最好不要添加新的第三方库或框架.
编辑:澄清,显然method.isAnnotationPresent(InstallerMethod.class)将是检查方法是否具有注释的方法 - 但是这个问题包括找到所有方法.