Java Reflection Method Invoke invokeMethod(Method method, Object target)

Here you can find the source of invokeMethod(Method method, Object target)

Description

Invokes the given method on the passed target.

License

Apache License

Parameter

Parameter Description
method Method to invoke per reflection.
target Object on which to invoke the method.

Exception

Parameter Description
InvocationTargetException If invocation target is invalid.
IllegalArgumentException If arguments are invalid.
IllegalAccessException If method cannot be accessed.

Return

The result object.

Declaration

public static Object invokeMethod(Method method, Object target)
        throws IllegalAccessException, IllegalArgumentException, InvocationTargetException 

Method Source Code

//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);
    }
}

Related

  1. invokeMethod(Method method, Object bean, Object[] values)
  2. invokeMethod(Method method, Object instance, Object... parameters)
  3. invokeMethod(Method method, Object object)
  4. invokeMethod(Method method, Object object, Object... args)
  5. invokeMethod(Method method, Object object, Object... arguments)
  6. invokeMethod(Method method, Object target)
  7. invokeMethod(Method method, Object target)
  8. invokeMethod(Method method, Object target, Class expectedType)
  9. invokeMethod(Method method, Object target, Object... args)