Java Utililty Methods Reflection Method Static Invoke

List of utility methods to do Reflection Method Static Invoke

Description

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

Method

TinvokeDefaultStaticMethod(Class expectedClass, String className, String methodName)
invoke Default Static Method
Class<?> cls = classForName(className);
try {
    Method m = cls.getMethod(methodName, new Class[] {});
    T t = (T) m.invoke(null, new Object[] {});
    if (t == null) {
        return t;
    if (expectedClass.isAssignableFrom(t.getClass()) == false) {
...
ObjectinvokeReflectStaticMethod(String methodName, Class cl, Object[] parameter, Class[] args)
invoke Reflect Static Method
try {
    Method method = cl.getDeclaredMethod(methodName, args);
    method.setAccessible(true);
    return method.invoke(null, parameter);
} catch (Exception e) {
    e.printStackTrace();
if (isThrowable) {
...
TinvokeStatic(Class clazz, String methodName, Class returnClass, Object... args)
invoke Static
try {
    Method method = clazz.getMethod(methodName);
    method.setAccessible(true);
    return (T) method.invoke(null, args);
} catch (Exception e) {
    throw new RuntimeException(e);
ObjectinvokeStatic(final Class clazz, final String methodName, final Class[] argTypes, final Object[] args)
Invokes a static method on a class.
final Method method = clazz.getMethod(methodName, argTypes);
return method.invoke(null, args);
TinvokeStatic(final ClassLoader loader, final String className, final String methodName, final Object... parameters)
Invokes a static method of a given class.
final Class<?> clazz = loader.loadClass(className);
for (final Method method : clazz.getMethods()) {
    if (method.getName().equals(methodName) && doParametersMatch(method.getParameterTypes(), parameters)) {
        return (T) method.invoke(null, parameters);
throw new NoSuchMethodException("No matching method found");
OinvokeStatic(final String className, final String methodName, final I argument)
invoke Static
try {
    final Class<?> clazz = Class.forName(className);
    final Class<?> argumentClass = argument.getClass();
    final Method method = clazz.getDeclaredMethod(methodName, argumentClass);
    return (O) method.invoke(null, argument);
} catch (final Exception ex) {
    return handleReflectionException(ex);
ObjectinvokeStatic(String cname, String methodName, ClassLoader cl)
invoke Static
return invokeStatic(cname, methodName, cl, EmptyClassArray, EmptyObjectArray);
ObjectinvokeStaticClass(Class staticClass, String methodName, Object[] args, Class... parameterTypes)
invoke Static Class
Method method = null;
try {
    method = staticClass.getMethod(methodName, parameterTypes);
} catch (SecurityException e) {
    log.error("Can't get method " + methodName, e);
    return null;
} catch (NoSuchMethodException e) {
    log.error("Can't get method " + methodName, e);
...
ObjectinvokeStaticMethod(Class objClass, String methodName, Object args[])
invoke Static Method
Object result = null;
try {
    Class argClasses[] = null;
    if (args != null && args.length > 0) {
        argClasses = new Class[args.length];
        for (int i = 0, max = args.length; i < max; i++) {
            argClasses[i] = (args[i] == null) ? null : args[i].getClass();
    Method method = getMethod(objClass, methodName, argClasses);
    result = method.invoke(null, args);
} catch (Exception e) {
return result;
ObjectinvokeStaticMethod(Class cls, String method, Class[] params, Object... args)
Invokes a static method
try {
    return getMethod(cls, method, params).invoke(null, args);
} catch (IllegalAccessException e) {
    e.printStackTrace();
} catch (IllegalArgumentException e) {
    e.printStackTrace();
} catch (InvocationTargetException e) {
    e.printStackTrace();
...