get Interface Annotation - Java java.lang.annotation

Java examples for java.lang.annotation:Annotation Attribute

Description

get Interface Annotation

Demo Code


//package com.java2s;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class Main {
    public static <T extends Annotation> T getInterfaceAnnotation(
            Method method, Class<T> annotationClass) {
        for (Class<?> iface : method.getDeclaringClass().getInterfaces()) {
            try {
                Method m = iface.getMethod(method.getName(),
                        method.getParameterTypes());
                return m.getAnnotation(annotationClass);
            } catch (NoSuchMethodException ignore) {
            }/*from  ww w  . j  av a2 s.c om*/
        }
        return null;
    }
}

Related Tutorials