Here you can find the source of getMethod(Class> clazz, String name, int paramlength)
public static Method getMethod(Class<?> clazz, String name, int paramlength)
//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; } }