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 aClass, String methodName, Class[] parameterTypesToCheck, Class stopClass)
get Method
while (aClass != null && aClass != stopClass) {
    Method[] methods = aClass.getDeclaredMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        if (method.getName().equals(methodName) && !Modifier.isAbstract(method.getModifiers())) {
            Class[] parameterTypes = method.getParameterTypes();
            if (parameterTypes.length == 0 && parameterTypesToCheck == null) {
                return method;
...
MethodgetMethod(Class aClass, String name, Class... parameters)
get Method
return findMethod(aClass.getMethods(), name, parameters);
MethodgetMethod(Class cl, String methodName, String obfName, Class... parameterTypes)
get Method
Method m = null;
try {
    try {
        m = cl.getDeclaredMethod(methodName, parameterTypes);
    } catch (Exception e) {
    if (m == null)
        m = cl.getDeclaredMethod(obfName, parameterTypes);
...
MethodgetMethod(Class clazz, String methodName, Class... parameterTypes)
We cannot use clazz.getMethod(String name, Class...
Class currentClass = clazz;
while (currentClass != null) {
    try {
        Method method = currentClass.getDeclaredMethod(methodName, parameterTypes);
        method.setAccessible(true);
        return method;
    } catch (NoSuchMethodException e) {
        currentClass = currentClass.getSuperclass();
...
MethodgetMethod(Class clazz, String methodName, Class... parameterTypes)
Search the method in the class and it's parent classes.
return _getMethod(null, clazz, methodName, parameterTypes);
MethodgetMethod(Class clazz, String name, Class... parameterTypes)
Util method to get a method, ignoring checked exceptions
Method method = null;
try {
    method = clazz.getMethod(name, parameterTypes);
} catch (Exception e) {
    e.printStackTrace();
return method;
MethodgetMethod(Class clazz, String name, Class[] parameters)
get Method
for (Method method : clazz.getMethods()) {
    if (name.equals(method.getName()) && isAssignable(method.getParameterTypes(), parameters))
        return method;
return clazz.getMethod(name, parameters);
MethodgetMethod(Class declaringClass, String name, Class... parameterTypes)
Convenience for getting a method from a class.
try {
    return declaringClass.getMethod(name, parameterTypes);
} catch (Exception ex) {
    throw new RuntimeException(ex);
MethodgetMethod(Class klass, String methodName, Class[] parameterTypes)
Returns the method object identified by the specified class, name and paramater types.
try {
    return klass.getDeclaredMethod(methodName, parameterTypes);
} catch (NoSuchMethodException e) {
    if (klass.equals(Object.class))
        return null;
    return getMethod(klass.getSuperclass(), methodName, parameterTypes);
MethodgetMethod(Class target, String methodName, Class[] parameterTypes)
get Method
return findMethod(target.getClass().getMethods(), methodName, parameterTypes);