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

TinvokeVirtual(String methodName, Object onObj, Class[] declaredArgTypes, Object... withArgs)
invoke Virtual
Class clazz = onObj.getClass();
while (clazz != null) {
    final Method method = clazz.getDeclaredMethod(methodName, declaredArgTypes);
    if (method != null) {
        method.setAccessible(true);
        return (T) method.invoke(onObj, withArgs);
    clazz = clazz.getSuperclass();
...
RinvokeVirtual(T o, Method method, Object... pa)
Invoke a virtual Method method .
try {
    return (R) method.invoke(o, pa);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
    throw new RuntimeException();
voidinvokeVoid(MethodHandle mh)
invoke Void
mh.invokeExact();
voidinvokeVoidNoArgMethod(Class declaringClass, String methodName, Object instance)
invoke Void No Arg Method
Method method = declaringClass.getDeclaredMethod(methodName);
method.setAccessible(true);
method.invoke(instance);
voidinvokeVoidSafe(Object obj, String methodName, Class paramClass, Object param)
invoke Void Safe
try {
    Method method = obj.getClass().getMethod(methodName, paramClass);
    method.invoke(obj, param);
} catch (SecurityException e) {
} catch (NoSuchMethodException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
...
ObjectinvokeWithoutDeclaredExceptions(Method method, Object target, Object... args)
invoke Without Declared Exceptions
try {
    return doInvoke(method, target, args);
} catch (Throwable t) {
    throw uncheck(t);
voidinvokeWithoutInvocationException(Method m, Object obj, Object... args)
Invokes the given void method on the given object with the given arguments.
try {
    invoke(m, obj, args);
} catch (InvocationTargetException e) {
    throw new RuntimeException(new RuntimeException(e.getTargetException().toString()));