Java Reflection Method Name getMethods(final Class clazz, final String methodName)

Here you can find the source of getMethods(final Class clazz, final String methodName)

Description

Find at the class all methods where its name be equals to the method name as parameter.

License

Open Source License

Parameter

Parameter Description
clazz a parameter
methodName a parameter

Return

a list's method with method name as parameter.

Declaration

public static List<Method> getMethods(final Class<?> clazz, final String methodName) 

Method Source Code

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

import java.lang.reflect.Method;

import java.util.ArrayList;

import java.util.List;

public class Main {
    /** Find at the object all method where its name be equals to the method name as parameter.
     *    It returns a list with all methods with the same name, but with differents parameters.
     *//from w  ww .j  av a 2s . c om
     * @param obj
     * @param methodName
     * @return a list's method with method name as parameter.
     */
    public static List<Method> getMethods(final Object obj, final String methodName) {
        return getMethods(obj.getClass(), methodName);
    }

    /** Find at the class all methods where its name be equals to the method name as parameter.
     * It returns a list with all methods with the same name, but with differents parameteres.
     *
     * @param clazz
     * @param methodName
     * @return a list's method with method name as parameter.
     */
    public static List<Method> getMethods(final Class<?> clazz, final String methodName) {
        Method[] arrayMethod = clazz.getMethods();
        List<Method> resultMethodList = new ArrayList<Method>();
        for (Method currentMethod : arrayMethod) {
            if (currentMethod.getName().equalsIgnoreCase(methodName)) {
                resultMethodList.add(currentMethod);
            }
        }
        return resultMethodList;
    }
}

Related

  1. getMethodOrNull(Class cls, String name, Class[] args)
  2. getMethodPropertyName(java.lang.reflect.Method method)
  3. getMethods(Class clazz, String name, int args)
  4. getMethods(Class type, String name)
  5. getMethods(final Class cl, final String name, final int params)
  6. getMethods(String classname)
  7. getMethodsByName(Class cls, String methodName)
  8. getMethodSubjectName(Method method)
  9. getMethodsWithName(Class clazz, String name)