Пример #1
0
 /** Invoke a method on an object using reflection. */
 public static Object invoke(final Object target, final Method method, final Object... args) {
   try {
     return AccessController.doPrivileged(
         new PrivilegedExceptionAction<Object>() {
           public Object run() throws IllegalAccessException, InvocationTargetException {
             if (!method.isAccessible())
               method.setAccessible(
                   true); // Say please - else invoke() will fail if method is protected
             return method.invoke(target, args);
           }
         });
   } catch (PrivilegedActionException e) {
     e.printStackTrace();
   }
   return null;
 }