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

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

Description

Searches for the method within class hierarchy

License

Apache License

Declaration

public static Method getMethodFromClassHierarchy(Class<?> clazz, String methodName)
        throws NoSuchMethodException 

Method Source Code

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

import java.lang.reflect.Method;

public class Main {
    /**/*from w ww . j a v  a  2 s  .  co m*/
     * Searches for the method within class hierarchy
     *
     * @return
     */
    public static Method getMethodFromClassHierarchy(Class<?> clazz, String methodName)
            throws NoSuchMethodException {
        while (clazz != null) {
            for (Method method : clazz.getDeclaredMethods()) {
                if (method.getName().equals(methodName)) {
                    return method;
                }
            }
            clazz = clazz.getSuperclass(); //NOSONAR
        }
        throw new NoSuchMethodException(methodName);
    }
}

Related

  1. getMethodByNameSimple(Class clz, String methodName)
  2. getMethodCount(Class clazz, String methodName)
  3. getMethodCountForName(Class clazz, String methodName)
  4. getMethodExceptionType(Class cls, String methodName, Class[] argTypes, int methodPosition, int classPosition, Class defaultType)
  5. getMethodFromClass(Class cls, String methodName, Class argClass, boolean onlyProtectedAndHigher)
  6. getMethodFromClassWithInheritance(Class cls, String methodName)
  7. getMethodFullName(Method method)
  8. getMethodIfAvailable(Class clazz, String methodName, Class... paramTypes)
  9. getMethodIfAvailable(Class clazz, String methodName, Class... paramTypes)