Here you can find the source of invoke(Method method, Object obj, Object... args)
Parameter | Description |
---|---|
method | method to invoke |
obj | object to invoke |
args | arguments of the method |
Parameter | Description |
---|---|
IllegalAccessException | if this Method objectis enforcing Java language access control and the underlyingmethod is inaccessible. |
InvocationTargetException | if the underlying methodthrows an exception. |
public static Object invoke(Method method, Object obj, Object... args) throws InvocationTargetException, IllegalAccessException
//package com.java2s; //License from project: Apache License import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { /**/*from www .j ava 2s . c o m*/ * Invoke the method event if not accessible. * * @param method method to invoke * @param obj object to invoke * @param args arguments of the method * @return return value from the method invocation * @throws IllegalAccessException if this {@code Method} object * is enforcing Java language access control and the underlying * method is inaccessible. * @throws InvocationTargetException if the underlying method * throws an exception. * @see Method#invoke(Object, Object...) */ public static Object invoke(Method method, Object obj, Object... args) throws InvocationTargetException, IllegalAccessException { boolean accessible = method.isAccessible(); if (accessible) { return method.invoke(obj, args); } method.setAccessible(true); try { return method.invoke(obj, args); } finally { method.setAccessible(accessible); } } }