Here you can find the source of invokePrivate(String name, final Object obj, Object[] objects)
public static Object invokePrivate(String name, final Object obj, Object[] objects) throws 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 invokePrivate(String name, final Object obj, Object[] objects) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Method method = null;/*from w w w . ja v a2s . c om*/ Class<?> objClass = obj instanceof Class ? (Class<?>) obj : obj .getClass(); while (objClass != null && method == null) { for (Method m : objClass.getDeclaredMethods()) { if (name.equals(m.getName()) && (objects == null && m.getParameterTypes().length == 0) || (objects != null && objects.length == m .getParameterTypes().length)) { method = m; break; } } objClass = objClass.getSuperclass(); } if (method == null) { throw new IllegalArgumentException("method with name " + name + " was not found, check class definition."); } final boolean wasAccessible = method.isAccessible(); try { method.setAccessible(true); return method.invoke(obj, objects); } finally { if (wasAccessible != method.isAccessible()) { method.setAccessible(wasAccessible); } } } }