Java Method Call invoke(final Object instance, final String methodName, final Class[] methodParams, final Object[] args)

Here you can find the source of invoke(final Object instance, final String methodName, final Class[] methodParams, final Object[] args)

Description

invoke

License

Apache License

Declaration

@SuppressWarnings("rawtypes")
    public static Object invoke(final Object instance, final String methodName, final Class[] methodParams,
            final Object[] args) throws Exception 

Method Source Code

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

import java.lang.reflect.Method;

public class Main {
    @SuppressWarnings("rawtypes")
    public static Object invoke(final Object instance, final String methodName, final Class[] methodParams,
            final Object[] args) throws Exception {
        Class<? extends Object> cl = instance.getClass();
        Method method = cl.getDeclaredMethod(methodName, methodParams);
        method.setAccessible(true);/* w w  w .  j  ava  2 s. c  o  m*/
        Object result = method.invoke(instance, args);
        return result;
    }

    public static Object invoke(final Object instance, final String methodName) throws Exception {
        Class<? extends Object> cl = instance.getClass();
        Method method = cl.getDeclaredMethod(methodName, new Class[0]);
        method.setAccessible(true);
        Object result = method.invoke(instance, new Object[0]);
        return result;
    }
}

Related

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