Java Reflection Annotation getAnnotation(Class clazz, Method method, int parameterIndex)

Here you can find the source of getAnnotation(Class clazz, Method method, int parameterIndex)

Description

get Annotation

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <T extends Annotation> T getAnnotation(Class<T> clazz, Method method, int parameterIndex) 

Method Source Code


//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;
    }
}

Related

  1. getAnnotation(Class a, Class c)
  2. getAnnotation(Class annotation, Class ownerClass, Method method)
  3. getAnnotation(Class annotationClass, Class cls)
  4. getAnnotation(Class annotationType, AnnotatedElement... objects)
  5. getAnnotation(Class cl, Object o)
  6. getAnnotation(Class cls, Annotation... annotations)
  7. getAnnotation(Class cls, Method... methods)
  8. getAnnotation(Class lookingFor, Annotation[] annotations)
  9. getAnnotation(Enum enumConstant, Class annotationClass)