Java Reflection Method Invoke invokeMethod(Method method, Object theObject, Object[] args)

Here you can find the source of invokeMethod(Method method, Object theObject, Object[] args)

Description

Invokes a method on the specified object with the specified parameters.

License

Open Source License

Parameter

Parameter Description
method the method to invoke
theObject object to invoke the method on
args parameters for the method call

Exception

Parameter Description
Throwable if the underlying method throws an exception

Return

result of invoking the method

Declaration

public static Object invokeMethod(Method method, Object theObject, Object[] args) throws Throwable 

Method Source Code


//package com.java2s;
/*-/*from  www .j av  a2s .  c o  m*/
 * Copyright ? 2009 Diamond Light Source Ltd., Science and Technology
 * Facilities Council
 *
 * This file is part of GDA.
 *
 * GDA is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License version 3 as published by the Free
 * Software Foundation.
 *
 * GDA is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along
 * with GDA. If not, see <http://www.gnu.org/licenses/>.
 */

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
    /**
     * Invokes a method on the specified object with the specified parameters.
     * If the underlying method throws an exception, it is rethrown.
     * 
     * @param method the method to invoke
     * @param theObject object to invoke the method on
     * @param args parameters for the method call
     * 
     * @return result of invoking the method
     * 
     * @throws Throwable if the underlying method throws an exception
     */
    public static Object invokeMethod(Method method, Object theObject, Object[] args) throws Throwable {
        try {
            return method.invoke(theObject, args);
        } catch (InvocationTargetException e) {
            throw e.getTargetException();
        }
    }
}

Related

  1. invokeMethod(Method method, Object target, Object... args)
  2. invokeMethod(Method method, Object target, Object... arguments)
  3. invokeMethod(Method method, Object target, Object... params)
  4. invokeMethod(Method method, Object target, Object[] args)
  5. invokeMethod(Method method, Object target, Object[] args)
  6. invokeMethod(Method method, Object... arguments)
  7. invokeMethod(Object bean, Method method, Object... param)
  8. invokeMethod(Object bean, Method method, Object[] args)
  9. invokeMethod(Object caller, Object classInstance, String className, String methodName, String parameterClasses[], Object[] parameters)