Are Java meta annotations available at runtime?

I created a meta annotation and applied it to the annotation, but cannot find a way to find which meta annotations are associated with the annotation at runtime. Is this really supported in JDK 6?

eg:.

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

It’s easy to find methods with the “TypeOne” annotation, but as soon as I get this annotation in my hand, how can I find out at runtime whether this annotation has a related meta-annotation (ie, “Filter”)?

+3
source share
1 answer

I already have an answer:

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

+3
source

Source: https://habr.com/ru/post/1754601/


All Articles