Here you can find the source of findAnnotation(Class> clazz, Class
Parameter | Description |
---|---|
clazz | The class to scan. |
annotationType | The annotation type to find. |
public static <T extends Annotation> T findAnnotation(Class<?> clazz, Class<T> annotationType)
//package com.java2s; //License from project: LGPL import java.lang.annotation.Annotation; public class Main { /**/*from w w w .j a v a2s . co m*/ * Look for the annotationType in the class or one of its ancestors. * * @param clazz The class to scan. * @param annotationType The annotation type to find. * @return The annotation, null if not found. */ public static <T extends Annotation> T findAnnotation(Class<?> clazz, Class<T> annotationType) { T a = clazz.getAnnotation(annotationType); if (a != null) { return a; } Class<?> parentClass = clazz.getSuperclass(); if (parentClass != null && !parentClass.equals(Object.class)) { a = findAnnotation(parentClass, annotationType); } if (a == null) { for (Class<?> i : clazz.getInterfaces()) { a = findAnnotation(i, annotationType); if (a != null) { return a; } } } return a; } }