Here you can find the source of getAnnotation(Class> clazz, Class
public static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> annotationType)
//package com.java2s; //License from project: Open Source License import java.lang.annotation.Annotation; public class Main { public static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> annotationType) { T result = clazz.getAnnotation(annotationType); if (result == null) { Class<?> superclass = clazz.getSuperclass(); if (superclass != null) { return getAnnotation(superclass, annotationType); } else { return null; }/*from ww w . j a va 2 s . com*/ } else { return result; } } }