Here you can find the source of getAnnotations(AnnotatedElement ae, Class
public static <T extends Annotation> Collection<T> getAnnotations(AnnotatedElement ae, Class<T> annotationType)
//package com.java2s; //License from project: Apache License import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; import java.util.ArrayList; import java.util.Collection; public class Main { public static <T extends Annotation> Collection<T> getAnnotations(AnnotatedElement ae, Class<T> annotationType) { Collection<T> anns = new ArrayList<>(2); // look at raw annotation T ann = ae.getAnnotation(annotationType); if (ann != null) { anns.add(ann);/*from w w w . ja va 2 s. c o m*/ } // scan meta-annotations for (Annotation metaAnn : ae.getAnnotations()) { ann = metaAnn.annotationType().getAnnotation(annotationType); if (ann != null) { anns.add(ann); } } return (anns.isEmpty() ? null : anns); } }