Here you can find the source of getAnnotation(AnnotatedElement ae, Class
Parameter | Description |
---|---|
ae | the Method, Constructor or Field from which to get the annotation |
annotationType | the annotation class to look for, both locally and as a meta-annotation |
public static <T extends Annotation> T getAnnotation(AnnotatedElement ae, Class<T> annotationType)
//package com.java2s; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; public class Main { /**/*from ww w . j a va 2 s . c o m*/ * Get a single {@link Annotation} of {@code annotationType} from the supplied * Method, Constructor or Field. Meta-annotations will be searched if the annotation * is not declared locally on the supplied element. * @param ae the Method, Constructor or Field from which to get the annotation * @param annotationType the annotation class to look for, both locally and as a meta-annotation * @return the matching annotation or {@code null} if not found * @since 3.1 */ public static <T extends Annotation> T getAnnotation(AnnotatedElement ae, Class<T> annotationType) { T ann = ae.getAnnotation(annotationType); if (ann == null) { for (Annotation metaAnn : ae.getAnnotations()) { ann = metaAnn.annotationType().getAnnotation(annotationType); if (ann != null) { break; } } } return ann; } }