Java Utililty Methods Method Call

List of utility methods to do Method Call

Description

The list of methods to do Method Call are organized into topic(s).

Method

Objectinvoke(Object bean, Method method, Object value)
invoke
try {
    return method.invoke(bean, value);
} catch (Exception e) {
return value;
voidinvoke(Object bean, Method method, Object value)
invoke
Object[] values = { value };
invoke(bean, method, values);
Objectinvoke(Object bean, String methodName, Object args, Class parameterType)
invoke
Class<?> serviceClass = null;
Method businessMethod = null;
Object obj = null;
try {
    serviceClass = bean.getClass();
    businessMethod = serviceClass.getMethod(methodName, parameterType);
    obj = businessMethod.invoke(bean, args);
} catch (Exception e) {
...
Objectinvoke(Object buffer, String methodName, Class[] paramTypes, Object... args)
invoke
Method method = null;
try {
    method = buffer.getClass().getMethod(methodName, paramTypes);
} catch (Exception e) {
    Method[] methods = buffer.getClass().getMethods();
    for (Method m : methods) {
        if (m.getName().equals(methodName)) {
            method = m;
...
Objectinvoke(Object clazzInstance, String method, Class[] paramClasses, Object[] params)
invoke
Method _m = clazzInstance.getClass().getMethod(method, paramClasses);
return _m.invoke(clazzInstance, params);
voidinvoke(Object context, String methodName, Object parameter)
invoke
try {
    Class methodHodler = context.getClass();
    Method method = methodHodler.getMethod(methodName, parameter.getClass());
    method.invoke(context, parameter);
} catch (NoSuchMethodException e) {
    e.printStackTrace();
} catch (IllegalAccessException e) {
    e.printStackTrace();
...
Objectinvoke(Object host, String method, Object[] args)
invoke
Class clz = host.getClass();
for (Method m : clz.getMethods()) {
    if (m.getName().equals(method) && m.getParameterCount() == args.length) {
        Class[] paramTypes = m.getParameterTypes();
        for (int i = 0; i < paramTypes.length; ++i)
            args[i] = rectifyValue(paramTypes[i], args[i]);
        return m.invoke(host, args);
return null;
Objectinvoke(Object instance, java.lang.reflect.Method method, Object... args)
invoke
try {
    return method.invoke(instance, args);
} catch (IllegalAccessException iae) {
    throw new RuntimeException(getDetail(instance, method, args), iae);
} catch (java.lang.reflect.InvocationTargetException ite) {
    throw new RuntimeException(getDetail(instance, method, args), ite);
} catch (RuntimeException re) {
    throw new RuntimeException(getDetail(instance, method, args), re);
...
Objectinvoke(Object instance, Method method, Object... params)
Invokes the given object Method .
return method.invoke(instance, params);
Objectinvoke(Object instance, String method, Class[] paramTypes, Object... parameters)
invoke
Class clazz = instance.getClass();
for (Method m : clazz.getMethods()) {
    if (m.getName().equals(method) && Arrays.equals(m.getParameterTypes(), paramTypes)) {
        try {
            return m.invoke(instance, parameters);
        } catch (Exception e) {
            throw new RuntimeException("Can't invoke method", e);
throw new RuntimeException("Can't find method");