Here you can find the source of findAnnotationDeclaringClass(Class annotationType, Class clazz)
public static Class findAnnotationDeclaringClass(Class annotationType, Class clazz)
//package com.java2s; import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.Iterator; public class Main { public static Class findAnnotationDeclaringClass(Class annotationType, Class clazz) { if (clazz == null || clazz.equals(Object.class)) return null; else/*www .jav a2s. c om*/ return isAnnotationDeclaredLocally(annotationType, clazz) ? clazz : findAnnotationDeclaringClass(annotationType, clazz.getSuperclass()); } public static boolean isAnnotationDeclaredLocally(Class annotationType, Class clazz) { boolean declaredLocally = false; Iterator iterator = Arrays.asList(clazz.getDeclaredAnnotations()).iterator(); do { if (!iterator.hasNext()) break; Annotation annotation = (Annotation) iterator.next(); if (!annotation.annotationType().equals(annotationType)) continue; declaredLocally = true; break; } while (true); return declaredLocally; } }