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 clazz, String name, Class[] parameterTypes)
Returns a matching method for the given name and parameters on the given class If the parameterTypes arguments is null it will return the first matching method on the class.
return getMethod(clazz, name, parameterTypes, false);
java.lang.reflect.MethodgetMethod(Class cls, String name, Class... parameterTypes)
get Method
try {
    return cls.getMethod(name, parameterTypes);
} catch (NoSuchMethodException nsme) {
    throw new RuntimeException(nsme);
MethodgetMethod(Class clz, String methodName, Class... parameterTypes)
get Method
try {
    Method m = clz.getDeclaredMethod(methodName, parameterTypes);
    return m;
} catch (NoSuchMethodException | SecurityException e) {
    return getMethodByNameSimple(clz, methodName);
MethodgetMethod(Class declaringClass, String name, Class... parameterTypes)
get Method
try {
    if (parameterTypes == null) {
        Method found = null;
        for (Method m : declaringClass.getDeclaredMethods()) {
            if (m.getName().equals(name)) {
                if (found != null) {
                    throw new RuntimeException(
                            "more than one method named " + name + " in " + declaringClass);
...
MethodgetMethod(Class declaringType, String methodName, Class... parameterTypes)
Finds a method by name and parameter types.
return findMethod(declaringType, methodName, parameterTypes);
MethodgetMethod(Class instance, String method, Class... parameters)
get Method
if (instance != null && method != null) {
    try {
        return instance.getMethod(method, parameters);
    } catch (Exception e) {
        e.printStackTrace();
return null;
...
MethodgetMethod(Class sourceClass, boolean isFindDeclaredMethod, boolean isUpwardFind, String methodName, Class... methodParameterTypes)
get Method
Method method = null;
try {
    method = isFindDeclaredMethod ? sourceClass.getDeclaredMethod(methodName, methodParameterTypes)
            : sourceClass.getMethod(methodName, methodParameterTypes);
} catch (NoSuchMethodException e1) {
    if (isUpwardFind) {
        Class<?> classs = sourceClass.getSuperclass();
        while (method == null && classs != null) {
...
MethodgetMethod(Class target, String methodName, Class... parameterTypes)
get Method
try {
    Method m = target.getDeclaredMethod(methodName, parameterTypes);
    if (m != null) {
        return m;
    } else {
        return target.equals(Object.class) ? null
                : getMethod(target.getSuperclass(), methodName, parameterTypes);
} catch (Exception e) {
    return target.equals(Object.class) ? null
            : getMethod(target.getSuperclass(), methodName, parameterTypes);
MethodgetMethod(Class type, String name, Class... parametersType)
Retrieve a method from a given class or one of its superclass.
try {
    return type.getMethod(name, parametersType);
} catch (NoSuchMethodException e) {
    if (!Object.class.equals(type.getSuperclass())) {
        return getMethod(type.getSuperclass(), name, parametersType);
    throw new NoSuchMethodException();
MethodgetMethod(Class type, String name, Class... parameterTypes)
get Method
try {
    return myGetMethod(type, name, parameterTypes);
} catch (NoSuchMethodException e) {
    throw new RuntimeException(e);