List of utility methods to do Reflection Method Invoke
Object | invoke(Method method, Object obj, Object... args) Invoke the method event if not accessible. boolean accessible = method.isAccessible(); if (accessible) { return method.invoke(obj, args); method.setAccessible(true); try { return method.invoke(obj, args); } finally { ... |
Object | invoke(Method method, Object object, Object... args) Invoke. try { return method.invoke(object, args); } catch (final InvocationTargetException e) { if (e.getCause() instanceof Exception) { throw (Exception) e.getCause(); } else if (e.getCause() instanceof Error) { throw (Error) e.getCause(); } else { ... |
Object | invoke(Method method, Object object, Object... arguments) invoke Object result = null; try { if (!method.isAccessible()) { method.setAccessible(true); result = method.invoke(object, arguments); } catch (Exception ignored) { System.err.printf("%s method[arguments : %s] can't be invoked in object[%s]!\n", method.getName(), ... |
Object | invoke(Method method, Object object, Object... arguments) invoke return execute(() -> { method.setAccessible(true); return method.invoke(object, arguments); }); |
T | invoke(Method method, Object object, Object... parameters) Invoke a method on an object and return whatever it returns. try { return (T) method.invoke(object, parameters); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof IOException) ... |
Object | invoke(Method method, Object object, Object[] args, Class invoke try { return method.invoke(object, args); } catch (IllegalAccessException e) { throw handleException(exceptionToThrow, e); } catch (InvocationTargetException e) { throw handleException(exceptionToThrow, e); |
T | invoke(Method method, Object target, Object... args) invoke try { return (T) method.invoke(target, args); } catch (Exception ex) { throw new IllegalArgumentException("Cannot invoke method " + method, ex); |
Object | invoke(Method method, Object target, Object... arguments) Invoke a method of the provided target with the provided arguments. try { return method.invoke(target, arguments); } catch (Exception e) { throw new RuntimeException(e); |
Object | invoke(Method method, T instance, Object... params) invoke try { if (params == null) { return method.invoke(instance); } else { return method.invoke(instance, params); } catch (Exception e) { return null; ... |
T | invoke(MethodHandle methodHandle, Object... params) Wraps any non-runtime exceptions with a runtime exception try { return (T) methodHandle.invokeWithArguments(params); } catch (RuntimeException e) { throw e; } catch (Throwable throwable) { throw new RuntimeException(throwable); |