Java Utililty Methods Reflection Method Invoke

List of utility methods to do Reflection Method Invoke

Description

The list of methods to do Reflection Method Invoke are organized into topic(s).

Method

Objectinvoke(Method m, Object o, Object[] args)
Reflection helper methods.
try {
    return m.invoke(o, args);
} catch (IllegalAccessException iae) {
    throw new RuntimeException(iae);
} catch (IllegalArgumentException iae) {
    throw new RuntimeException(iae);
Objectinvoke(Method m, Object o, String msg, Object... parameters)
invoke
try {
    return m.invoke(o, parameters);
} catch (InvocationTargetException e) {
    Throwable t = e.getTargetException();
    if (t instanceof Error) {
        throw (Error) t;
    throw new ReflectionException((Exception) t, "Exception thrown while invoking  " + msg);
...
Objectinvoke(Method m, Object target, Object... params)
invoke
try {
    m.setAccessible(true);
    return m.invoke(target, params);
} catch (Exception e) {
    throw new RuntimeException(e);
longinvoke(Method method)
invoke
try {
    Object value = (method == null) ? null : method.invoke(osBean);
    return (value == null) ? VALUE_UNAVAILABLE : ((Number) value).longValue();
} catch (Throwable t) {
    return VALUE_UNAVAILABLE;
voidinvoke(Method method)
invoke
method.getModifiers();
Objectinvoke(Method method, Object data, Object... arguments)
Common method to invoke Method with reflection
Object value;
try {
    value = method.invoke(data, arguments);
} catch (IllegalAccessException ex) {
    throw new IOException(ex);
} catch (IllegalArgumentException ex) {
    throw new IOException(ex);
} catch (InvocationTargetException ex) {
...
Tinvoke(Method method, Object instance, Object... parameters)
Invoke the method.
if (!method.isAccessible())
    method.setAccessible(true);
if (Modifier.isStatic(method.getModifiers()) && instance != null)
    instance = null;
try {
    return (T) method.invoke(instance, parameters);
} catch (IllegalAccessException e) {
    throw new RuntimeException("Failed to invoke method", e);
...
Objectinvoke(Method method, Object it, Object... args)
Invokes the specified method on the given it Object with the given arguments.
try {
    method.setAccessible(true);
    return method.invoke(it, args);
} catch (IllegalArgumentException e) {
    throw new Error(
            String.format("Method '%s' rejected arguments(%s)", method.getName(), argumentList(args)), e);
} catch (IllegalAccessException e) {
    throw new Error("Method became inaccessible.", e);
...
Objectinvoke(Method method, Object javaBean, Object value)
invoke
Object[] paramValue = null;
if (value == paramValue) {
    paramValue = new Object[0];
} else {
    paramValue = new Object[] { value };
try {
    return method.invoke(javaBean, paramValue);
...
Objectinvoke(Method method, Object obj, Object... args)
invoke
try {
    return method.invoke(obj, args);
} catch (IllegalAccessException e) {
    throw new IllegalArgumentException("Can't invoke method " + method.getName(), e);
} catch (InvocationTargetException e) {
    throw new IllegalArgumentException("Can't invoke method " + method.getName(), e);