Here you can find the source of getMethod(Class> clazz, String functionName, Class>[] parameterTypes)
public static Method getMethod(Class<?> clazz, String functionName, Class<?>[] parameterTypes)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; public class Main { public static Method getMethod(Class<?> clazz, String functionName, Class<?>[] parameterTypes) { try {//from www . ja v a 2 s . c o m Method function = clazz.getDeclaredMethod(functionName, parameterTypes); return function; } catch (Exception e) { if (parameterTypes.length > 0) { Method[] fList = clazz.getDeclaredMethods(); loop: for (Method md : fList) { Class<?>[] paramTypes = md.getParameterTypes(); if (!md.getName().equals(functionName)) continue loop; if (paramTypes.length != parameterTypes.length) continue loop; for (int i = 0; i < parameterTypes.length; i++) { if (!paramTypes[i].isAssignableFrom(parameterTypes[i])) continue loop; } return md; } } Class<?> superClazz = clazz.getSuperclass(); if (superClazz == Object.class) { return null; } else { return getMethod(superClazz, functionName, parameterTypes); } } } }