Java Utililty Methods Reflection Method Name

List of utility methods to do Reflection Method Name

Description

The list of methods to do Reflection Method Name are organized into topic(s).

Method

MethodgetMethodByName(Class clazz, String methodName)
get Method By Name
for (Method m : clazz.getMethods()) {
    if (m.getName().equals(methodName)) {
        return m;
throw new IllegalStateException(
        "Expected '" + methodName + "' method not found on interface '" + clazz.getName());
MethodgetMethodByName(Class aClass, String methodName, Class... params)
Retrieves a method by name (grabs the first if overloaded).
Method result = null;
try {
    result = aClass.getMethod(methodName, params);
} catch (Exception e) {
return (result);
MethodgetMethodByName(Class clazz, String methodName)
get Method By Name
Method[] methods = clazz.getDeclaredMethods();
if (methods == null || methods.length == 0) {
    return null;
if (methodName == null || methodName.length() == 0) {
    return null;
List<Method> methodList = new ArrayList<Method>();
...
MethodgetMethodByName(Class clazz, String methodName)
get Method By Name
List<Method> methodsFound = new ArrayList<Method>();
for (Method method : clazz.getMethods()) {
    if (method.getName().equals(methodName)) {
        methodsFound.add(method);
if (methodsFound.size() == 1) {
    return methodsFound.get(0);
...
MethodgetMethodByName(Class clazz, String name)
get Method By Name
Method method = getPublicMethodByName(clazz, name);
if (method != null)
    return method;
method = getProtectedMethodByName(clazz, name);
if (method != null)
    return method;
return null;
MethodgetMethodByName(Class cls, String methodName)
Find that one method.
List<Method> methods = getMethodsByName(cls, methodName);
if (methods.size() == 0) {
    throw new NoSuchMethodException(methodName + " on " + cls);
if (methods.size() > 1) {
    throw new RuntimeException("Doh! Too many methods named " + methodName + " on " + cls);
return methods.get(0);
...
MethodgetMethodByName(Class type, String methodName)
Searches for a public method in the specified class or its superclasses and -interfaces that matches the specified name and has no parameters.
try {
    return type.getMethod(methodName);
} catch (NoSuchMethodException e) {
    return null;
MethodgetMethodByName(final Class cls, final String action)
Return the method that exactly match the action name.
for (final Method m : cls.getMethods()) {
    if (m.getName().equals(action)) {
        return m;
throw new NoSuchMethodException(action);
MethodgetMethodByNameFromArray(Method[] methods, String methodName)
get Method By Name From Array
Method method = null;
if (methods != null && methods.length > 0) {
    for (Method m : methods) {
        if (methodName.equalsIgnoreCase(m.getName())) {
            System.out.println("getMethodByNameFromArray: Found method " + methodName);
            return m;
return method;
MethodgetMethodByNameSimple(Class clz, String methodName)
get Method By Name Simple
Method[] methods = clz.getDeclaredMethods();
for (Method method : methods) {
    if (method.getName().equals(methodName)) {
        return method;
return null;