Here you can find the source of invokeMethods(final Object target, final List
Parameter | Description |
---|---|
target | the target object. |
methods | the methods to invoke. |
Parameter | Description |
---|---|
InvocationTargetException | if one of the underlying method throws an exception |
IllegalArgumentException | if the method is an instance method and the specified object argument is not aninstance of the class or interface declaring the underlying method (or of a subclassor implementor thereof); if the number of actual and formal parameters differ; if anunwrapping conversion for primitive arguments fails; or if, after possibleunwrapping, a parameter value cannot be converted to the corresponding formalparameter type by a method invocation conversion. |
IllegalAccessException | if one of the Method object is enforcing Java language access control and the underlyingmethod is inaccessible. |
public static List<Object> invokeMethods(final Object target, final List<Method> methods) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
//package com.java2s; //License from project: Open Source License import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; public class Main { /**//from w w w .ja v a2 s. co m * Invoke the following list of methods (with no parameter) and return the result in a * {@link List}. * @param target * the target object. * @param methods * the methods to invoke. * @return the result of the method call. * @throws InvocationTargetException * if one of the underlying method throws an exception * @throws IllegalArgumentException * if the method is an instance method and the specified object argument is not an * instance of the class or interface declaring the underlying method (or of a subclass * or implementor thereof); if the number of actual and formal parameters differ; if an * unwrapping conversion for primitive arguments fails; or if, after possible * unwrapping, a parameter value cannot be converted to the corresponding formal * parameter type by a method invocation conversion. * @throws IllegalAccessException * if one of the Method object is enforcing Java language access control and the underlying * method is inaccessible. */ public static List<Object> invokeMethods(final Object target, final List<Method> methods) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { final List<Object> results = new ArrayList<>(methods.size()); for (final Method method : methods) { results.add(method.invoke(target, (Object[]) null)); } return results; } }