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

ObjectinvokeJdbcMethod(Method method, Object target)
Invoke the specified JDBC API Method against the supplied target object with no arguments.
return invokeJdbcMethod(method, target, new Object[0]);
ObjectinvokeJdbcMethod(Method method, Object target)
Invoke the specified JDBC API Method against the supplied target object with no arguments.
return invokeJdbcMethod(method, target, new Object[0]);
ObjectinvokeMethod(Class clazz, Object classObject, String methodName, Class[] paramTypes, Object... args)
invoke Method
try {
    if (paramTypes == null) {
        paramTypes = new Class[args.length];
        for (int i = 0; i < args.length; i++) {
            if (args[i] instanceof Integer) {
                paramTypes[i] = int.class;
            } else {
                paramTypes[i] = args[i].getClass();
...
ObjectinvokeMethod(Class clazz, Object obj, String methodName, Class[] parametersTypes, Object[] parameters)
Invokes specified method using reflection and returns result.
Method method = clazz.getDeclaredMethod(methodName, parametersTypes);
method.setAccessible(true);
return method.invoke(obj, parameters);
ObjectinvokeMethod(Class clazz, String methodName, Object[] args)
invoke Method
return invokeMethod(clazz, null, methodName, args);
ObjectinvokeMethod(Class targetClass, Object obj, String methodName, Object arg)
invoke Method
Object result = null;
try {
    Class argClasses[] = null;
    if (arg != null)
        argClasses = new Class[] { arg.getClass() };
    Method method = getMethod(targetClass, methodName, argClasses);
    result = method.invoke(obj, new Object[] { arg });
} catch (Exception e) {
...
ObjectinvokeMethod(Class clazz, E instance, String[] names, Object... args)
invoke Method
try {
    Method method = getMethod(clazz, names);
    if (method != null)
        return method.invoke(instance, args);
} catch (Exception ex) {
    ex.printStackTrace();
return null;
...
ObjectinvokeMethod(Class clazz, Object object, String methodName, Class[] parameterTypes, Object[] parameters)
invoke Method
Method method = getDeclaredMethod(clazz, methodName, parameterTypes);
if (method == null) {
    throw new RuntimeException("Method `" + methodName + "` not found in class `" + clazz.getName() + "`.");
if (!method.isAccessible()) {
    method.setAccessible(true);
try {
...
voidinvokeMethod(Class clazz, String method, Class[] args, Object object, Object[] objects)
invoke Method
try {
    Method m = clazz.getDeclaredMethod(method, args);
    m.setAccessible(true);
    m.invoke(object, objects);
} catch (Exception ex) {
ObjectinvokeMethod(Class clz, String methodName, Object... params)
Invoke a non-public static method by name from a class.
Method method = getMethod(clz, methodName, params);
return invokeMethod(null, method, params);