Here you can find the source of getMethod(Class> parentClass, Class> returnType, String methodName, Class>... types)
public static Method getMethod(Class<?> parentClass, Class<?> returnType, String methodName, Class<?>... types)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; public class Main { public static Method getMethod(Class<?> parentClass, Class<?> returnType, String methodName, Class<?>... types) { for (Method method : parentClass.getDeclaredMethods()) { if (equalsTo(method, returnType, methodName, types)) return method; }//from w w w . j a v a 2 s. c o m return null; } private static boolean equalsTo(Method otherMethod, Class<?> returnType, String methodName, Class<?>... methodTypes) { if (methodName != null && !methodName.equals(otherMethod.getName())) return false; if (otherMethod.getParameterCount() != methodTypes.length) return false; // not equal methods if (!otherMethod.getReturnType().equals(returnType)) return false; for (int i = 0; i < otherMethod.getParameterTypes().length; i++) { if (otherMethod.getParameterTypes()[i] != methodTypes[i]) return false; } return true; } }