Here you can find the source of invoke(Method method, Object object, Object... arguments)
public static Object invoke(Method method, Object object, Object... arguments)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.concurrent.Callable; public class Main { public static Object invoke(Method method, Object object, Object... arguments) { return execute(() -> { method.setAccessible(true);//from w w w .ja va2s . c o m return method.invoke(object, arguments); }); } public static <T> T execute(Callable<T> reflectiveCall) { try { return reflectiveCall.call(); } catch (RuntimeException rte) { throw rte; } catch (InvocationTargetException ite) { if (ite.getCause() instanceof RuntimeException) { throw (RuntimeException) ite.getCause(); } throw new IllegalStateException(ite.getCause()); } catch (Exception shouldNotHappen) { throw new IllegalStateException(shouldNotHappen); } } }