Java Reflection Method Parameter getMethodsWith(Class c, Class... parameters)

Here you can find the source of getMethodsWith(Class c, Class... parameters)

Description

Returns a method from a class with the given parameters

License

Open Source License

Parameter

Parameter Description
c The class
parameters Which parameters should be checked

Return

The found method

Declaration

public static List<Method> getMethodsWith(Class<?> c, Class<?>... parameters) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    /**//from  w w w. ja v  a 2 s  .co  m
     * Returns a method from a class with the given parameters
     *
     * @param c The class
     * @param parameters Which parameters should be checked
     * @return The found method
     */
    public static List<Method> getMethodsWith(Class<?> c, Class<?>... parameters) {
        List<Class<?>> params = Arrays.asList(parameters);
        List<Method> methods = new ArrayList<>();

        for (Method m : c.getMethods()) {
            for (Class<?> p : m.getParameterTypes()) {
                if (params.contains(p))
                    methods.add(m);
            }
        }

        return methods;
    }
}

Related

  1. getMethodParameters(final Method method, final Map generics)
  2. getMethodParametersType(Class clazz, String methodName)
  3. getMethodParameterTypes(final Method method)
  4. getMethodQuietly(Class clazz, String methodName, Class... parameterTypes)
  5. getMethodRecursive(final Class clazz, final String methodName, final Class... parameterTypes)
  6. getMethodUp(Class type, String name, Class... parameterTypes)
  7. getMethodWithParameter(Class declaringClass, Class parameterClass)