我创建了一个元注解并将其应用于注解,但无法找到任何方法在运行时查找与注解相关联的元注解。 JDK 6是否支持此功能?
例如:
/**
* Meta-annotation for other annotations declaring them to be "filter" annotations
*/
@Target(ElementType.ANNOTATION_TYPE) // make this a meta-annotation
@Retention(RetentionPolicy.RUNTIME) // available at runtime
public @interface Filter
{
}
/**
* Marks a test as only being applicable to TypeOne clients
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Filter
public @interface TypeOne
{
}
public class MyClientClass
{
// Would like to scan this method to see if the method has an Annotation that is of meta-type "Filter"
@TypeOne
public void testMethod()
{
}
}
找到带有“TypeOne”注解的方法很简单,但是一旦我得到了该注解,如何在运行时找出它是否具有相关联的元注解(例如,“Filter”)?