get Methods With Annotation - Java java.lang.annotation

Java examples for java.lang.annotation:Method Annotation

Description

get Methods With Annotation

Demo Code


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

public class Main {

    public static List<Method> getMethodsWithAnnotation(Class<?> klass,
            Class<? extends Annotation> annotation) {
        List<Method> methodList = new ArrayList<Method>();

        for (Method m : klass.getMethods()) {
            if (m.isAnnotationPresent(annotation)) {
                methodList.add(m);//from  w  w  w.  java  2  s .c o  m
            }
        }

        return methodList;
    }
}

Related Tutorials