Here you can find the source of invokeMethod(Method inMethod, Object inObject, Object[] inArgs)
public static Object invokeMethod(Method inMethod, Object inObject, Object[] inArgs) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
//package com.java2s; //License from project: Open Source License import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { public static Object invokeMethod(Method inMethod, Object inObject, Object[] inArgs) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { final boolean isAccessible = inMethod.isAccessible(); if (!isAccessible) { inMethod.setAccessible(true); }/*ww w . ja v a 2s. com*/ try { return inMethod.invoke(inObject, inArgs); } finally { // why reset this beahviour; will setAccessible(true) anyways again on next invocation // if (!isAccessible) { // inMethod.setAccessible(false); // } } } }