Here you can find the source of invokePrivateMethod(Method method, Object object, Object... args)
public static Object invokePrivateMethod(Method method, Object object, Object... args)
//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 invokePrivateMethod(Method method, Object object, Object... args) { //Used to be private try {/*from ww w . java 2s . co m*/ method.setAccessible(true); return method.invoke(object, args); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { return null; } finally { method.setAccessible(false); } } }