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

ObjectinvokeStaticMethod(Class cls, String methodName, Object... args)
invoke Static Method
int arguments = args.length;
Class<?>[] parameterTypes = new Class[arguments];
for (int i = 0; i < arguments; i++) {
    parameterTypes[i] = args[i].getClass();
Method method = cls.getMethod(methodName, parameterTypes);
return method.invoke(null, args);
TinvokeStaticMethod(Class cls, String name)
invoke Static Method
return invokeStaticMethod(cls, name, null);
MethodinvokeStaticMethod(Class klass, String methodName)
invoke Static Method
if (klass == null) {
    throw new NoSuchMethodException();
Method method = klass.getMethod(methodName, null);
method.setAccessible(true);
return method;
ObjectinvokeStaticMethod(Class objectType, String name, Class paramTypes[], Object args[])
invoke Static Method
Method method = objectType.getMethod(name, paramTypes);
if (!method.isAccessible()) {
    method.setAccessible(true);
try {
    return method.invoke(null, args);
} catch (InvocationTargetException e) {
    throw e.getTargetException();
...
ObjectinvokeStaticMethod(Class pClass, String pMethod, Object pParam)
Gets an object from any given static method, with the given parameter.
return invokeStaticMethod(pClass, pMethod, new Object[] { pParam });
ObjectinvokeStaticMethod(final Class cls, final String methodName)
Invoke the named static method.
if (cls != null) {
    try {
        final Method method = cls.getDeclaredMethod(methodName);
        if (!method.isAccessible()) {
            method.setAccessible(true);
        return method.invoke(null);
    } catch (final NoSuchMethodException e) {
...
ObjectinvokeStaticMethod(final Class cls, final String methodName, final boolean throwException)
Invoke the named static method.
if (cls != null) {
    try {
        final Method method = cls.getDeclaredMethod(methodName);
        try {
            method.setAccessible(true);
        } catch (final Exception e) {
        return method.invoke(null);
...
TinvokeStaticMethod(final Class clazz, final String methodName, final Class[] parameterTypes, final Object[] arglist)
Call the specified static method on the given class, using the given arguments.
Method method = clazz.getMethod(methodName, parameterTypes);
return clazz.cast(method.invoke(null, arglist)); 
ObjectinvokeStaticMethod(final Method method, final Object... args)
Invoke the specified static Method with the supplied arguments.
if (method == null) {
    throw new IllegalArgumentException("Method must not be null.");
if (!Modifier.isStatic(method.getModifiers())) {
    throw new IllegalArgumentException("Method must be static.");
method.setAccessible(true);
return method.invoke(null, args);
...
ObjectinvokeStaticMethod(String className, String method, Class[] paramTypes, Object[] paramValues)
invoke a static method on a class.
Class clz = Class.forName(className);
Method m = clz.getDeclaredMethod(method, paramTypes);
return m.invoke(null, paramValues);