hasMetaAnnotationTypes
方法定义
/**
* @param element AnnotatedElement对象(Class,Method,Field)
* @param annotationType 指定查找的元注解类型
* @return {@code true} if a matching meta-annotation is present
* @see #getMetaAnnotationTypes
*/
public static boolean hasMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType);
hasMetaAnnotationTypes方法判断提供的AnnotatedElement对象(Class,Method,Field)是否用复合注解类型进行注解,而该复合注解是用annotationType指定的注解作元注解的。
示例:
元注解 @CellLogTag
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE,ElementType.METHOD})
public @interface CellLogTag {
}
使用 @CellLogTag
的作元注解的复合注解 @TestLogTag
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@CellLogTag
public @interface TestLogTag {
}
调用示例:
@Test
public void test6HasMetaAnnotationTypes() {
try {
Method method = ClassB.class.getMethod("m0");
boolean has = AnnotatedElementUtils.hasMetaAnnotationTypes(method,CellLogTag.class);
assertTrue(has);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
public static class ClassB {
@TestLogTag()
public void m0() {};
}