Java Reflection Method Invoke invokeMethod(Method inMethod, Object inObject, Object[] inArgs)

Here you can find the source of invokeMethod(Method inMethod, Object inObject, Object[] inArgs)

Description

invoke Method

License

Open Source License

Declaration

public static Object invokeMethod(Method inMethod, Object inObject, Object[] inArgs)
            throws IllegalAccessException, IllegalArgumentException, InvocationTargetException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static Object invokeMethod(Method inMethod, Object inObject, Object[] inArgs)
            throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {

        final boolean isAccessible = inMethod.isAccessible();
        if (!isAccessible) {
            inMethod.setAccessible(true);
        }/*ww w .  ja v a  2s.  com*/

        try {

            return inMethod.invoke(inObject, inArgs);

        } finally {

            // why reset this beahviour; will setAccessible(true) anyways again on next invocation
            //         if (!isAccessible) {
            //            inMethod.setAccessible(false);
            //         }
        }
    }
}

Related

  1. invokeMethod(final Object obj, final String methodName, final boolean throwException)
  2. invokeMethod(final Object object, final String methodName, final Class[] parameterTypes, final Object[] parameters)
  3. invokeMethod(final Object object, final String methodName, final Class[] paramTypes, final Object[] parameters)
  4. invokeMethod(final Object p, final String methodName)
  5. invokeMethod(java.lang.Object toObj, String tcMethodName, Class toResultClass)
  6. invokeMethod(Method m, Object instance, Object[] args)
  7. invokeMethod(Method m, Object[] o)
  8. invokeMethod(Method meth, String str)
  9. invokeMethod(Method method, Class beanClass, Object element)