AnnotationUtils.java 文件源码

java
阅读 44 收藏 0 点赞 0 评论 0

项目:holon-core 作者:
/**
 * Get all the annotations of given <code>annotationType</code> present in given <code>element</code>, including any
 * meta-annotation and supporting repeatable annotations.
 * @param <A> Annotation type
 * @param element Annotated element to inspect (not null)
 * @param annotationType Annotation type to lookup
 * @return List of detected annotation of given <code>annotationType</code>, an empty List if none found
 */
public static <A extends Annotation> List<A> getAnnotations(AnnotatedElement element, Class<A> annotationType) {
    ObjectUtils.argumentNotNull(element, "AnnotatedElement must be not null");
    ObjectUtils.argumentNotNull(annotationType, "Annotation type must be not null");

    Class<? extends Annotation> repeatableContainerType = null;
    if (annotationType.isAnnotationPresent(Repeatable.class)) {
        repeatableContainerType = annotationType.getAnnotation(Repeatable.class).value();
    }

    List<A> annotations = new LinkedList<>();
    findAnnotations(annotations, element, annotationType, repeatableContainerType);
    return annotations;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号