Here you can find the source of findAnnotation(Class> clazz, Class annotationClass)
public static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationClass)
//package com.java2s; //License from project: Apache License import java.lang.annotation.Annotation; public class Main { public static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationClass) { A annotation = clazz.getAnnotation(annotationClass); if (null != annotation) { return annotation; }/* ww w. j a va 2s . com*/ for (Class<?> ifc : clazz.getInterfaces()) { annotation = ifc.getAnnotation(annotationClass); if (null != annotation) { return annotation; } } Class<?> superclass = clazz.getSuperclass(); if (superclass == null || superclass.equals(Object.class)) { return null; } return findAnnotation(superclass, annotationClass); } }