Java Reflection Method Invoke invokeMethodWithKnownParamTypes(Object object, String methodName, Class[] methodParamTypes, Object... args)

Here you can find the source of invokeMethodWithKnownParamTypes(Object object, String methodName, Class[] methodParamTypes, Object... args)

Description

invoke Method With Known Param Types

License

Apache License

Declaration

public static Object invokeMethodWithKnownParamTypes(Object object, String methodName, Class[] methodParamTypes,
            Object... args) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static Object invokeMethodWithKnownParamTypes(Object object, String methodName, Class[] methodParamTypes,
            Object... args) {/*from   www  . j a v  a2 s . c  o  m*/
        Throwable t = null;
        try {
            Class clazz = object.getClass();
            Method setter = clazz.getMethod(methodName, methodParamTypes);
            return setter.invoke(object, args);
        } catch (NoSuchMethodException e) {
            t = e;
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            t = e;
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            t = e;
            e.printStackTrace();
        }
        throw new RuntimeException("Invoke failed", t);
    }
}

Related

  1. invokeMethodOnObject(Object target, String methodName)
  2. invokeMethodQuietly(Object receiver, Method method, Object... args)
  3. invokeMethods(final Object target, final List methods)
  4. invokeMethodsWithAnnotation(final Class annotation, final Object instance, final Object... args)
  5. invokeMethodWithArray2(Object target, Method method, Object[] args)
  6. invokeMethodWithNoArgs(Object o, Method method)
  7. invokeMethodWithoutException(Object object, String methodName, Class[] parameterTypes, Object[] parameters)