Java Reflection Method Name getMethod(Class clazz, String name, int paramlength)

Here you can find the source of getMethod(Class clazz, String name, int paramlength)

Description

get Method

License

Open Source License

Declaration

public static Method getMethod(Class<?> clazz, String name, int paramlength) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.AccessibleObject;

import java.lang.reflect.Method;

public class Main {
    public static Method getMethod(Class<?> clazz, String name, int paramlength) {
        do {/*ww  w.  j a  v a 2s  . c om*/
            for (Method method : clazz.getDeclaredMethods()) {
                if (method.getName().equals(name) && (method.getParameterTypes().length == paramlength)) {
                    return setAccessible(method);
                }
            }
        } while ((clazz = clazz.getSuperclass()) != null);
        throw new RuntimeException("Can't find method " + name + " with params length " + paramlength);
    }

    public static <T extends AccessibleObject> T setAccessible(T object) {
        object.setAccessible(true);
        return object;
    }
}

Related

  1. getMethod(Class clazz, String name)
  2. getMethod(Class clazz, String name, boolean declared, Class... args)
  3. getMethod(Class clazz, String name, Class... args)
  4. getMethod(Class clazz, String name, Class... args)
  5. getMethod(Class clazz, String name, Class... params)
  6. getMethod(Class clazz, String... names)
  7. getMethod(Class cls, String name)
  8. getMethod(Class cls, String name)
  9. getMethod(Class cls, String name, Class... types)