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

Tinvoke(Object object, String methodName, Class returnType, Object... parameters)
Invoke a method.
Class<?>[] parameterTypes = new Class<?>[parameters.length];
for (int i = 0; i < parameters.length; i++) {
    parameterTypes[i] = parameters[i] == null ? Object.class : parameters[i].getClass();
Method method = object.getClass().getDeclaredMethod(methodName, parameterTypes);
method.setAccessible(true);
return returnType.cast(method.invoke(object, parameters));
Objectinvoke(Object object, String methodName, Object[] args)
invoke
if (object == null) {
    throw new NullPointerException();
Method method = getMatchingMethod(object.getClass(), methodName, args);
return method.invoke(object, args);
Objectinvoke(Object objToInvoke, Class classToInvoke, String method, Class[] argumentClasses, Object[] arguments)
Invoke a method via reflection
Method m = classToInvoke.getDeclaredMethod(method, argumentClasses);
Object o;
if (m.isAccessible())
    o = m.invoke(objToInvoke, arguments);
else {
    m.setAccessible(true);
    o = m.invoke(objToInvoke, arguments);
    m.setAccessible(false);
...
Tinvoke(Object owner, String methodName)
invoke
Method m;
try {
    m = owner.getClass().getDeclaredMethod(methodName);
} catch (NoSuchMethodException e) {
    throw new RuntimeException(e);
m.setAccessible(true);
try {
...
java.lang.Objectinvoke(Object proxy, java.lang.reflect.Method method, Object[] args)
invoke
return method.invoke(proxy, args);
Objectinvoke(Object source, String key)
invoke
if (source instanceof Map) {
    return valueOfMap((Map) source, key);
} else {
    return valueOfObj(source, key);
Objectinvoke(Object target, Class clazz, String methodName, Class[] parameterTypes, Object... args)
Convenience wrapper to reflection method invoke API.
try {
    Method method = null;
    try {
        method = clazz.getMethod(methodName, parameterTypes);
    } catch (NoSuchMethodException e) {
        method = clazz.getDeclaredMethod(methodName, parameterTypes);
    method.setAccessible(true);
...
Tinvoke(Object target, Class clazz, String method)
invoke
try {
    Method m = target.getClass().getMethod(method);
    return clazz.cast(m.invoke(target));
} catch (Throwable t) {
    throw new RuntimeException(t);
Objectinvoke(Object target, Method method)
invoke
requireNonNull(target, "target is null");
requireNonNull(method, "method is null");
try {
    return method.invoke(target);
} catch (InvocationTargetException e) {
    Throwable targetException = e.getTargetException();
    if (targetException instanceof RuntimeException) {
        throw new MBeanException((RuntimeException) targetException,
...
Objectinvoke(Object target, String methodName)
invoke
return invoke(target, methodName, NO_ARGS);