Here you can find the source of getAnnotation(Class> target, Class
Parameter | Description |
---|---|
clazz | The class to inspect. |
annotationClass | Class of the annotation to return |
public static <T extends Annotation> T getAnnotation(Class<?> target, Class<T> annotationClass)
//package com.java2s; //License from project: Apache License import java.lang.annotation.Annotation; public class Main { /**//from ww w. java 2s .c o m * Returns the annotation of the annotationClass of the clazz or any of it super classes. * * @param clazz * The class to inspect. * @param annotationClass * Class of the annotation to return * * @return The annotation of annnotationClass if found else null. */ public static <T extends Annotation> T getAnnotation(Class<?> target, Class<T> annotationClass) { Class<?> clazz = target; T annotation = clazz.getAnnotation(annotationClass); if (annotation != null) { return annotation; } while ((clazz = clazz.getSuperclass()) != null) { annotation = clazz.getAnnotation(annotationClass); if (annotation != null) { return annotation; } } return null; } }