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

voidinvokeProxied(final Callable callable, final ClassLoader classLoader)
Runs a Callable within a Proxy instance.
Callable<?> callableProxy = (Callable) Proxy.newProxyInstance(classLoader,
        new Class<?>[] { Callable.class }, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                callable.call();
                return null;
        });
...
voidinvokePublicMethod(Object o, String methodName, Class[] classes, Object[] objects)
invoke Public Method
try {
    Method m = o.getClass().getMethod(methodName, classes);
    m.setAccessible(true);
    m.invoke(o, objects);
} catch (Exception e) {
    e.printStackTrace();
voidinvokeQuietly(MethodHandle handle, Object instance)
invoke Quietly
try {
    handle.invoke(instance);
} catch (Throwable e) {
    e.printStackTrace();
ObjectinvokeQuietly(Object target, Method method, Object[] params)
invoke Quietly
Object result = null;
try {
    result = method.invoke(target, params);
} catch (InvocationTargetException invocationException) {
    for (Class<?> exceptionClass : method.getExceptionTypes()) {
        if (exceptionClass.isInstance(invocationException.getCause())) {
            throw invocationException.getCause();
        throw new IllegalStateException(invocationException.getCause());
return result;
ObjectinvokeReadResolveOn(Object object, Class clz)
If special method readResolve is available in this clz class, invoke it.
try {
    Method readResolved = clz.getDeclaredMethod("readResolve");
    if (readResolved != null) {
        readResolved.setAccessible(true);
        return readResolved.invoke(object);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
return null;
ObjectinvokeReal(Object real, Method m, Object[] args)
invoke Real
try {
    return m.invoke(real, args);
} catch (InvocationTargetException e) {
    throw e.getTargetException();
} catch (IllegalAccessException | IllegalArgumentException e) {
    throw new RuntimeException("unexpected invocation exception: " + e.getMessage());
RinvokeRemoteMBeanOperation(String remoteURL, String jmxName, Class klass, Function function)
invoke Remote M Bean Operation
JMXServiceURL jmxURL = new JMXServiceURL(remoteURL);
try (JMXConnector jmxc = JMXConnectorFactory.connect(jmxURL, null)) {
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    T remoteMBean = getMBean(jmxName, klass, mbsc);
    return function.apply(remoteMBean);
ObjectinvokeRestrictedMethod(Object obj, Class theClass, String methodName)
Call a private method without arguments.
return invokeRestrictedMethod(obj, theClass, methodName, (Object) null);
ObjectinvokeServiceClass(JsonReader jsonReader, Object service, Method operation, Class[] paramClasses, int paramCount)
invoke Service Class
Object[] methodParam = new Object[paramCount];
Gson gson = new Gson();
String[] argNames = new String[paramCount];
if (!jsonReader.isLenient()) {
    jsonReader.setLenient(true);
jsonReader.beginObject();
jsonReader.nextName(); 
...
voidinvokeSet(Object o, String fieldName, Object value)
invoke Set
Method method = getSetMethod(o.getClass(), fieldName);
try {
    method.invoke(o, new Object[] { value });
} catch (Exception e) {
    e.printStackTrace();