Here you can find the source of invokeMethod(Object obj, String methodname, Object... args)
public static void invokeMethod(Object obj, String methodname, Object... args)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; public class Main { public static void invokeMethod(Object obj, String methodname, Object... args) { Class<?> clazz = obj.getClass(); do {//from w w w. j a v a 2s.c om try { for (Method method : clazz.getDeclaredMethods()) { if (method.getName().equals(methodname) && method.getParameterTypes().length == args.length) { method.setAccessible(true); method.invoke(obj, args); } } } catch (Throwable t) { } } while ((clazz = clazz.getSuperclass()) != null); } }