Here you can find the source of getMethod(Class klazz, String[] methodNames, int argCount)
public static Method getMethod(Class klazz, String[] methodNames, int argCount)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; import java.util.ArrayList; public class Main { public static Method getMethod(Class klazz, String[] methodNames, int argCount) { if (klazz == null) { return null; }/*from w w w. j a v a 2 s. co m*/ for (String method : methodNames) { try { for (Method m : getAllMethods(klazz)) { if (m.getName().equals(method) && (argCount == -1 || m.getParameterTypes().length == argCount)) { m.setAccessible(true); return m; } } } catch (Exception e) { } } return null; } public static Method[] getAllMethods(Class clazz) { ArrayList<Method> methods = new ArrayList<Method>(); while (clazz != null) { for (Method m : clazz.getDeclaredMethods()) { methods.add(m); } clazz = clazz.getSuperclass(); } return methods.toArray(new Method[methods.size()]); } }