Java元注释在运行时可用吗?

Java元注释在运行时可用吗?,java,metadata,annotations,Java,Metadata,Annotations,我已经创建了一个元注释并将其应用于注释,但找不到任何方法在运行时找到与注释关联的元注释。JDK 6是否真的支持这一点 例如: 查找带有“TypeOne”注释的方法很简单,但一旦我手头有了该注释,我如何在运行时找出该注释是否具有关联的元注释(即“过滤器”)?我已经有了答案对不起: annotation.annotationType().isAnnotationPresent(Filter.class) /** * Meta-annotation for other annotations dec

我已经创建了一个元注释并将其应用于注释,但找不到任何方法在运行时找到与注释关联的元注释。JDK 6是否真的支持这一点

例如:


查找带有“TypeOne”注释的方法很简单,但一旦我手头有了该注释,我如何在运行时找出该注释是否具有关联的元注释(即“过滤器”)?

我已经有了答案对不起:

annotation.annotationType().isAnnotationPresent(Filter.class)

/**
 * 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()
   {
   }
}