Here you can find the source of getAnnotation(Class
@SuppressWarnings("unchecked") public static <T extends Annotation> T getAnnotation(Class<T> clazz, Method method, int parameterIndex)
//package com.java2s; //License from project: Open Source License import java.lang.annotation.Annotation; import java.lang.reflect.Method; public class Main { @SuppressWarnings("unchecked") public static <T extends Annotation> T getAnnotation(Class<T> clazz, Method method, int parameterIndex) { for (Annotation annotation : method.getParameterAnnotations()[parameterIndex]) { if (annotation.annotationType() == clazz) { return (T) annotation; }//from w ww . j av a2 s. c o m } return null; } }