Here you can find the source of invokeMethod(Object object, String name, Object... arguments)
public static Object invokeMethod(Object object, String name, Object... arguments) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
//package com.java2s; //License from project: Apache License import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { public static Object invokeMethod(Object object, String name, Object... arguments) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { Class<?> clazz = object.getClass(); Class<?> argumentClasses[] = new Class<?>[arguments.length]; for (int argumentId = 0; argumentId < arguments.length; argumentId++) { argumentClasses[argumentId] = arguments[argumentId].getClass(); }/*w ww.j a v a 2 s . c om*/ Method field = clazz.getDeclaredMethod(name, argumentClasses); boolean accessable = field.isAccessible(); if (!accessable) field.setAccessible(true); Object value = field.invoke(object, arguments); if (!accessable) field.setAccessible(false); return value; } }