Here you can find the source of getMethodsAnnotated(Class extends Annotation> anno, Class> holder)
public static List<Method> getMethodsAnnotated(Class<? extends Annotation> anno, Class<?> holder)
//package com.java2s; /*/*from w w w . ja v a2 s .c o m*/ * Copyright 2002-2006,2009 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { public static List<Method> getMethodsAnnotated(Class<? extends Annotation> anno, Class<?> holder) { ArrayList<Method> methods = new ArrayList<>(); List<Method> all = Arrays.asList(holder.getMethods()); all.stream().filter((method) -> (hasAnnotation(anno, method))).forEach((method) -> { methods.add(method); }); return methods; } public static List<Method> getMethodsAnnotated(Class<? extends Annotation> anno, Object holder) { ArrayList<Method> methods = new ArrayList<>(); List<Method> all = Arrays.asList(holder.getClass().getMethods()); all.stream().filter((method) -> (hasAnnotation(anno, method))).forEach((method) -> { methods.add(method); }); return methods; } public static Boolean hasAnnotation(Class<? extends Annotation> anno, Field field) { return field.isAnnotationPresent(anno); } public static Boolean hasAnnotation(Class<? extends Annotation> anno, Method meth) { return meth.isAnnotationPresent(anno); } public static Boolean hasAnnotation(Class<? extends Annotation> anno, Object obj) { return (getAnnotation(anno, obj) != null); } public static Boolean hasAnnotation(Class<? extends Annotation> anno, Class<?> cl) { return (getAnnotation(anno, cl) != null); } public static Annotation getAnnotation(Class<? extends Annotation> anno, Class<?> cl) { return cl.getAnnotation(anno); } public static Annotation getAnnotation(Class<? extends Annotation> anno, Object obj) { return obj.getClass().getAnnotation(anno); } public static Annotation getAnnotation(Class<? extends Annotation> anno, Method meth) { return meth.getAnnotation(anno); } public static Annotation getAnnotation(Class<? extends Annotation> anno, Field field) { return field.getAnnotation(anno); } }