Here you can find the source of invokeMethod(Method method, Object target)
Parameter | Description |
---|---|
method | Method to invoke per reflection. |
target | Object on which to invoke the method. |
Parameter | Description |
---|---|
InvocationTargetException | If invocation target is invalid. |
IllegalArgumentException | If arguments are invalid. |
IllegalAccessException | If method cannot be accessed. |
public static Object invokeMethod(Method method, Object target) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
//package com.java2s; //License from project: Apache License import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { /**//from w w w . ja v a 2 s. co m * Invokes the given method on the passed target. * * @param method * Method to invoke per reflection. * @param target * Object on which to invoke the method. * @return The result object. * @throws InvocationTargetException * If invocation target is invalid. * @throws IllegalArgumentException * If arguments are invalid. * @throws IllegalAccessException * If method cannot be accessed. */ public static Object invokeMethod(Method method, Object target) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { return invokeMethod(method, target, new Object[0]); } /** * Invokes the given method on the passed target with gieven arguments.. * * @param method * Method to invoke per reflection. * @param target * Object on which to invoke the method. * @param args * the method arguments * @return The result object. * @throws InvocationTargetException * If invocation target is invalid. * @throws IllegalArgumentException * If arguments are invalid. * @throws IllegalAccessException * If method cannot be accessed. */ public static Object invokeMethod(Method method, Object target, Object[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { return method.invoke(target, args); } }