Here you can find the source of getMethods(final Class> clazz, final Class extends Annotation> annotation)
Parameter | Description |
---|---|
clazz | the class to interrogate |
annotation | the annotation to find |
public static List<Method> getMethods(final Class<?> clazz, final Class<? extends Annotation> annotation)
//package com.java2s; /*// w w w . j av a 2 s . c om * Copyright (c) 2015 Jeremy Miller * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.LinkedList; import java.util.List; public class Main { /** * Return all method(s) of a specified class that contain the specified annotation. * @param clazz the class to interrogate * @param annotation the annotation to find * @return return the list of methods found (an empty list is possible) */ public static List<Method> getMethods(final Class<?> clazz, final Class<? extends Annotation> annotation) { final List<Method> annotatedMethods = new LinkedList<Method>(); for (Method method : clazz.getMethods()) { if (method.isAnnotationPresent(annotation)) { annotatedMethods.add(method); } } return annotatedMethods; } }