Here you can find the source of findAnnotation(Class> clazz, Class
public static <T extends Annotation> T findAnnotation(Class<?> clazz, Class<T> annotationClass)
//package com.java2s; // The MIT License (MIT) import java.lang.annotation.Annotation; public class Main { public static <T extends Annotation> T findAnnotation(Class<?> clazz, Class<T> annotationClass) { while (clazz != null) { T t = clazz.getAnnotation(annotationClass); if (t != null) { return t; }//from ww w . j a v a2 s .co m for (Class<?> interfaceClass : clazz.getInterfaces()) { t = interfaceClass.getAnnotation(annotationClass); if (t != null) { return t; } } clazz = clazz.getSuperclass(); } return null; } }