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

ObjectinvokeMethod(Method method, Object object, Object... arguments)
Fail-safe call.
try {
    return method.invoke(object, arguments);
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException e) {
} catch (InvocationTargetException e) {
return null;
ObjectinvokeMethod(Method method, Object target)
Invokes the given method on the passed target.
return invokeMethod(method, target, new Object[0]);
ObjectinvokeMethod(Method method, Object target)
invoke Method
return invokeMethod(method, target, new Object[0]);
ObjectinvokeMethod(Method method, Object target)
Invoke the specified Method against the supplied target object with no arguments.
return invokeMethod(method, target, new Object[0]);
TinvokeMethod(Method method, Object target, Class expectedType)
Invoke method and check the result.
Object result = method.invoke(target);
if (!expectedType.isInstance(result)) {
    throw new IllegalArgumentException(
            "Returned result must be instance of [" + expectedType.getName() + "]");
return expectedType.cast(result);
ObjectinvokeMethod(Method method, Object target, Object... args)
Invoke the specified Method against the supplied target object with the supplied arguments.
try {
    return method.invoke(target, args);
} catch (InvocationTargetException | IllegalAccessException e) {
    throw new IllegalStateException("Could not access method: " + e.getMessage());
ObjectinvokeMethod(Method method, Object target, Object... args)
invoke Method
Object obj = null;
try {
    obj = method.invoke(target, args);
} catch (IllegalAccessException e) {
    e.printStackTrace();
} catch (IllegalArgumentException e) {
    e.printStackTrace();
} catch (InvocationTargetException e) {
...
ObjectinvokeMethod(Method method, Object target, Object... arguments)
invoke Method
if (!method.isAccessible()) {
    method.setAccessible(true);
try {
    return method.invoke(target, arguments);
} catch (IllegalAccessException ex) {
    throw new RuntimeException("", ex);
ObjectinvokeMethod(Method method, Object target, Object... params)
Invoke a method on the given target instance using the provided parameters.
try {
    return method.invoke(target, params);
} catch (Exception e) {
    throw new RuntimeException("Unable to invoke method " + method + " for " + target, e);
ObjectinvokeMethod(Method method, Object target, Object[] args)
Invoke the specified Method against the supplied target object with the supplied arguments.
try {
    return method.invoke(target, args);
} catch (IllegalAccessException ex) {
    handleReflectionException(ex);
    throw new IllegalStateException(
            "Unexpected reflection exception - " + ex.getClass().getName() + ": " + ex.getMessage());
} catch (InvocationTargetException ex) {
    handleReflectionException(ex);
...