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(E e, String methodName)
invoke
return invoke(e, methodName, new Object[0]);
Objectinvoke(final Method m, final Object obj, final Object... args)
invoke
try {
    return m.invoke(obj, args);
} catch (final Exception e) {
    e.printStackTrace();
} catch (final Error e) {
    e.printStackTrace();
return null;
...
Objectinvoke(final Method method, final Object obj, final Object... args)
Invokes a method using reflection.
try {
    return method.invoke(obj, args);
} catch (final IllegalArgumentException e) {
    throw new RuntimeException(e);
} catch (final IllegalAccessException e) {
    throw new RuntimeException(e);
} catch (final InvocationTargetException e) {
    throw new RuntimeException(e);
...
voidinvoke(final Object component, final Method method, final Class type, final String value)
Invoke a method.
Object obj = valueOf(type, value);
method.invoke(component, obj);
Objectinvoke(final Object instance, final String method, final Object... parameters)
Execute a method by reflection.
final Class<?> clazz = instance.getClass();
for (final Method m : clazz.getMethods()) {
    if (m.getName().equals(method)) {
        try {
            return m.invoke(instance, parameters);
        } catch (final IllegalArgumentException | IllegalAccessException e) {
            throw new RuntimeException("Can't invoke method", e);
        } catch (final InvocationTargetException e) {
...
Objectinvoke(final Object instance, final String methodName, final Class[] methodParams, final Object[] args)
invoke
Class<? extends Object> cl = instance.getClass();
Method method = cl.getDeclaredMethod(methodName, methodParams);
method.setAccessible(true);
Object result = method.invoke(instance, args);
return result;
Objectinvoke(final Object object, final String methodName, final Class[] methodParamTypes, final Object[] methodParamValues)
invoke
Object result = null;
try {
    result = object.getClass().getMethod(methodName, methodParamTypes).invoke(object, methodParamValues);
} catch (InvocationTargetException ite) {
    Throwable t = ite.getTargetException();
    if (t instanceof Exception) {
        throw (Exception) t;
    throw ite;
} catch (Exception t) {
    t.printStackTrace();
return result;
Objectinvoke(final Object target, final Method method, final Object... parameters)
Invokes the method on the target object with the given parameters.
try {
    return method.invoke(target, parameters);
} catch (Exception e) {
    throw new RuntimeException("Failed invoking " + method, e);
Objectinvoke(final Object target, final Method method, final Object[] params)
invoke
try {
    method.setAccessible(true);
    return method.invoke(target, params);
} catch (IllegalArgumentException e) {
    throw new RuntimeException(e);
} catch (IllegalAccessException e) {
    throw new RuntimeException(e);
} catch (InvocationTargetException e) {
...
Tinvoke(Object _o, String _method, Object... _args)
Invokes a method.
ArrayList<Class<?>> inputs = new ArrayList<Class<?>>();
for (Object o : _args)
    inputs.add(o.getClass());
Method m = _o.getClass().getMethod(_method, inputs.toArray(new Class<?>[0]));
return (T) m.invoke(_o, _args);