Here you can find the source of getAnnotation(Class> clazz, Class
public static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> annClazz)
//package com.java2s; //License from project: Apache License import java.lang.annotation.Annotation; public class Main { public static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> annClazz) { while (clazz != null) { T ann = clazz.getAnnotation(annClazz); if (ann != null) { return ann; }//from www . j ava 2 s. co m clazz = clazz.getSuperclass(); } return null; } }