Here you can find the source of getMethod(Object o, String methodName, Class>[] args)
static public Method getMethod(Object o, String methodName, Class<?>[] args)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; public class Main { static public Method getMethod(Object o, String methodName, Class<?>[] args) { return getMethod(o.getClass(), methodName, args); }//from www.j a va2s.c o m static public Method getMethod(Class<?> clazz, String methodName, Class<?>[] args) { return getMethod(clazz, methodName, args, false); } static public Method getMethod(Class<?> clazz, String methodName, Class<?>[] args, boolean includePrivateMethods) { Method[] methods = null; // with Class.getDeclaredMethods(), private methods of the class are // also returned. // but the inherited methods are not returned which we get with // getMethods() if (includePrivateMethods) methods = clazz.getDeclaredMethods(); else methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(methodName) == false) continue; Class<?>[] declaredArgs = methods[i].getParameterTypes(); if (declaredArgs == null || declaredArgs.length == 0) { if (args == null) return methods[i]; continue; } if (args == null || declaredArgs.length != args.length) continue; boolean allArgsAssignable = true; for (int j = 0; j < declaredArgs.length; j++) { if (declaredArgs[j].isAssignableFrom(args[j]) == false) { allArgsAssignable = false; break; } } if (allArgsAssignable) return methods[i]; } return null; } }