Here you can find the source of invokeProtectedMethod(Class c, String method, Object... args)
public static Object invokeProtectedMethod(Class c, String method, Object... args)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; public class Main { public static Object invokeProtectedMethod(Class c, String method, Object... args) { return invokeProtectedMethod(c, null, method, args); }/*from w w w . j a v a2s .com*/ public static Object invokeProtectedMethod(Object o, String method, Object... args) { return invokeProtectedMethod(o.getClass(), o, method, args); } public static Object invokeProtectedMethod(Class c, Object o, String method, Object... args) { try { Class[] pTypes = new Class[args.length]; for (int i = 0; i < args.length; i++) { if (args[i] instanceof Integer) { pTypes[i] = int.class; } else { pTypes[i] = args[i].getClass(); } } Method m = c.getDeclaredMethod(method, pTypes); m.setAccessible(true); return m.invoke(o, args); } catch (Exception ex) { System.out.println("*** " + c.getName() + "." + method + "(): " + ex); return null; } } }