Here you can find the source of invoke(Object o, String method, Object... args)
public static Object invoke(Object o, String method, Object... args) throws Exception
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; public class Main { public static Object invoke(Object o, String method, Object... args) throws Exception { Class[] argTypes = new Class[args.length]; for (int i = 0; i < args.length; i++) { argTypes[i] = args.getClass(); }/*from ww w . j av a 2s . c o m*/ Method mthd = method(method, o.getClass()); mthd.setAccessible(true); return mthd.invoke(o, args); } private static Method method(String name, Class klass) throws NoSuchFieldException { if (klass == null) { return null; } Method[] fields = klass.getDeclaredMethods(); for (Method field : fields) { if (field.getName().equals(name)) { field.setAccessible(true); return field; } } return method(name, klass.getSuperclass()); } }