Java Reflection Method Name getMethodByName(Class clazz, String methodName)

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

Description

get Method By Name

License

Apache License

Declaration

public static Method getMethodByName(Class<?> clazz, String methodName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static Method getMethodByName(Class<?> clazz, String methodName) {
        Method[] methods = clazz.getDeclaredMethods();
        if (methods == null || methods.length == 0) {
            return null;
        }//  ww  w .j a v  a2s.com
        if (methodName == null || methodName.length() == 0) {
            return null;
        }
        List<Method> methodList = new ArrayList<Method>();
        for (Method method : methods) {
            if (method.getName().equals(methodName)) {
                methodList.add(method);
            }
        }
        if (methodList.size() == 0) {
            return null;
        }
        if (methodList.size() > 1) {
            return null;
        }
        return methodList.get(0);
    }
}

Related

  1. getMethod(String name, String methodDesc, Class actual)
  2. getMethod(String strMethodPrefix, A instance, String strAttributeName, Class clazz)
  3. getMethodAsAccessible(String methodName, Class clazz)
  4. getMethodByName(Class clazz, String methodName)
  5. getMethodByName(Class aClass, String methodName, Class... params)
  6. getMethodByName(Class clazz, String methodName)
  7. getMethodByName(Class clazz, String name)
  8. getMethodByName(Class cls, String methodName)
  9. getMethodByName(Class type, String methodName)