Here you can find the source of invokeMethod(Object target, Method method)
public static Object invokeMethod(Object target, Method method) 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(Object target, Method method) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (method.isAccessible()) { return method.invoke(target); } else {/*from www. j a v a2 s . c o m*/ method.setAccessible(true); Object rtn = method.invoke(target); method.setAccessible(false); return rtn; } } }