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

Einvoke(Object target, String methodName, Object... args)
invoke
for (Method method : target.getClass().getMethods()) {
    if (method.getName().equals(methodName)) {
        try {
            return (E) method.invoke(target, args);
        } catch (Exception e) {
            throw new RuntimeException("Exception invoking method " + methodName, e);
throw new RuntimeException("Method " + methodName + " not found");
Objectinvoke(Object target, String methodName, Object[] args)
invoke
try {
    Class<? extends Object> clazz = target.getClass();
    Method method = findMethod(clazz, methodName, args);
    method.setAccessible(true);
    return method.invoke(target, args);
} catch (Exception e) {
    throw new RuntimeException("couldn't invoke " + methodName + " on " + target, e);
Objectinvoke(Object target, String name, Class[] params, Object[] args)
Returns the result of invoking the method name on target with parameters params declared in the target's class using arguments args.
return invoke(target.getClass(), target, name, params, args);
Objectinvoke(Object targetObject, String method, Class[] paramTypes, Object[] paramValues)
invoke
String methodKey = getMethodKey(targetObject.getClass(), method, paramTypes);
Method methodObject = METHOD_CACHE.get(methodKey);
if (methodObject == null) {
    methodObject = targetObject.getClass().getMethod(method, paramTypes);
    if (methodObject != null) {
        METHOD_CACHE.put(methodKey, methodObject);
return methodObject.invoke(targetObject, paramValues);
Objectinvoke(Object targetObject, String methodName, Object... params)
invoke
return findMethod(targetObject.getClass(), methodName, params).invoke(targetObject, params);
Tinvoke(Object thisObject, Method method)
invoke
return (T) method.invoke(thisObject, NO_PARAM_SIGNATURE);
Objectinvoke(ObjectName objectName, Object[] params, String[] signature, String operationName)
invoke
Object result = platformMBeanServer.invoke(objectName, operationName, params, signature);
return result;
Tinvoke(ObjectName objectName, String attribute, Object[] params, String[] signatur)
invoke
try {
    return (T) mbeanServer.invoke(objectName, attribute, params, signatur);
} catch (MBeanException e) {
    throw new RuntimeException(e);
} catch (InstanceNotFoundException e) {
    throw new RuntimeException(e);
} catch (ReflectionException e) {
    throw new RuntimeException(e);
...
Optionalinvoke(Optional method, Class clazz, Object... args)
invoke
try {
    return invoke(method, clazz.newInstance(), args);
} catch (InstantiationException | IllegalAccessException e) {
    e.printStackTrace();
return Optional.empty();
Objectinvoke(String className, String methodName, Class[] paramTypes, Object... params)
invoke
return invoke(null, className, methodName, paramTypes, params);