Java Utililty Methods Reflection Method Parameter

List of utility methods to do Reflection Method Parameter

Description

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

Method

MethodgetMethod(Class type, String methodName, Class... parameterTypes)
Finds a method on a class.
Method method = null;
Class currentType = type;
while (method == null && !currentType.equals(Object.class)) {
    try {
        method = currentType.getDeclaredMethod(methodName, parameterTypes);
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
...
MethodgetMethod(Class type, String name, Class[] parameterTypes)
Returns the public method for the specified Class type, method name, and array of parameter types.
try {
    return type.getMethod(name, parameterTypes);
} catch (NoSuchMethodException e) {
    throw (Error) (new NoSuchMethodError(e.getMessage()).initCause(e));
MethodgetMethod(Class c, String methodName, Class... parameterTypes)
get Method
try {
    try {
        return c.getDeclaredMethod(methodName, parameterTypes);
    } catch (NoSuchMethodException ex) {
        Class<?> superclass = c.getSuperclass();
        if (superclass != null) {
            return getMethod(superclass, methodName, parameterTypes);
        return null;
} catch (RuntimeException ex) {
    throw ex;
} catch (Exception ex) {
    throw new RuntimeException("");
MethodgetMethod(Class clazz, String functionName, Class[] parameterTypes)
get Method
try {
    Method function = clazz.getDeclaredMethod(functionName, parameterTypes);
    return function;
} catch (Exception e) {
    if (parameterTypes.length > 0) {
        Method[] fList = clazz.getDeclaredMethods();
        loop: for (Method md : fList) {
            Class<?>[] paramTypes = md.getParameterTypes();
...
MethodgetMethod(Class clazz, String method, Class... parameterTypes)
get Method
try {
    Method m = clazz.getDeclaredMethod(method, parameterTypes);
    m.setAccessible(true);
    return m;
} catch (Exception ignored) {
    return null;
MethodgetMethod(Class clazz, String methodName, Class... parameterTypes)
get Method
String key = clazz + methodName;
Method method = methodMap.get(key);
if (method == null) {
    synchronized (clazz) {
        if (method == null) {
            try {
                method = clazz.getDeclaredMethod(methodName, parameterTypes);
                methodMap.put(key, method);
...
MethodgetMethod(Class clazz, String methodName, Class... parameterTypes)
get Method
try {
    return clazz.getMethod(methodName, parameterTypes);
} catch (NoSuchMethodException e) {
    throw new IllegalStateException("Java 8 or later but method " + clazz.getName() + "#" + methodName + "("
            + Arrays.toString(parameterTypes) + ") is missing", e);
MethodgetMethod(Class clazz, String methodName, Class... parameterTypes)
Get a method by reflection, and wrap all expected Exception as RuntimeException .
try {
    Method method = clazz.getDeclaredMethod(methodName, parameterTypes);
    method.setAccessible(true);
    return method;
} catch (NoSuchMethodException ex) {
    throw new IllegalStateException(ex);
MethodgetMethod(Class clazz, String name, Class... parameterTypes)
get Method
Method m = null;
try {
    m = clazz.getMethod(name, parameterTypes);
} catch (NoSuchMethodException e) {
return m;
MethodgetMethod(Class clazz, String name, Class... parameterTypes)
Searches all public, protected, package access, and private methods of a class and its superclasses for a method with the given name and parameter types.
while (clazz != null) {
    for (Method method : clazz.getDeclaredMethods()) {
        if (method.getName().equals(name)
                && Arrays.deepEquals(method.getParameterTypes(), parameterTypes)) {
            return method;
    clazz = clazz.getSuperclass();
...