Java Method Call invoke(Object bean, String methodName, Object args, Class parameterType)

Here you can find the source of invoke(Object bean, String methodName, Object args, Class parameterType)

Description

invoke

License

Open Source License

Declaration

public static Object invoke(Object bean, String methodName,
            Object args, Class<?> parameterType) 

Method Source Code

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

import java.lang.reflect.Method;

public class Main {
    public static Object invoke(Object bean, String methodName,
            Object args, Class<?> parameterType) {
        Class<?> serviceClass = null;
        Method businessMethod = null;
        Object obj = null;/*w  w  w  . j ava  2 s. c  o  m*/
        try {
            serviceClass = bean.getClass();
            businessMethod = serviceClass.getMethod(methodName,
                    parameterType);
            obj = businessMethod.invoke(bean, args);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return obj;
    }

    public static Object invoke(Object bean, String methodName,
            Object[] args, Class<?>... parameterTypes) {
        Class<?> serviceClass = null;
        Method businessMethod = null;
        Object obj = null;
        try {
            serviceClass = bean.getClass();
            businessMethod = serviceClass.getMethod(methodName,
                    parameterTypes);
            obj = businessMethod.invoke(bean, args);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return obj;
    }
}

Related

  1. invoke(final Object target, final Method method, final Object... parameters)
  2. invoke(final Object target, final Method method, final Object[] params)
  3. invoke(Object _o, String _method, Object... _args)
  4. invoke(Object bean, Method method, Object value)
  5. invoke(Object bean, Method method, Object value)
  6. invoke(Object buffer, String methodName, Class[] paramTypes, Object... args)
  7. invoke(Object clazzInstance, String method, Class[] paramClasses, Object[] params)
  8. invoke(Object context, String methodName, Object parameter)
  9. invoke(Object host, String method, Object[] args)