Java Method Call invoke(final Object target, final Method method, final Object... parameters)

Here you can find the source of invoke(final Object target, final Method method, final Object... parameters)

Description

Invokes the method on the target object with the given parameters.

License

Open Source License

Parameter

Parameter Description
target Target class that contains method.
method Method to invoke on target.
parameters Method parameters.

Return

Method return value. A void method returns null.

Declaration

public static Object invoke(final Object target, final Method method, final Object... parameters) 

Method Source Code


//package com.java2s;
/* See LICENSE for licensing and NOTICE for copyright. */

import java.lang.reflect.Method;

public class Main {
    /**//w ww  . j  a  v  a 2  s  . c  o  m
     * Invokes the method on the target object with the given parameters.
     *
     * @param  target  Target class that contains method.
     * @param  method  Method to invoke on target.
     * @param  parameters  Method parameters.
     *
     * @return  Method return value. A void method returns null.
     */
    public static Object invoke(final Object target, final Method method, final Object... parameters) {
        try {
            return method.invoke(target, parameters);
        } catch (Exception e) {
            throw new RuntimeException("Failed invoking " + method, e);
        }
    }
}

Related

  1. invoke(final Method method, final Object obj, final Object... args)
  2. invoke(final Object component, final Method method, final Class type, final String value)
  3. invoke(final Object instance, final String method, final Object... parameters)
  4. invoke(final Object instance, final String methodName, final Class[] methodParams, final Object[] args)
  5. invoke(final Object object, final String methodName, final Class[] methodParamTypes, final Object[] methodParamValues)
  6. invoke(final Object target, final Method method, final Object[] params)
  7. invoke(Object _o, String _method, Object... _args)
  8. invoke(Object bean, Method method, Object value)
  9. invoke(Object bean, Method method, Object value)