Java Reflection Method Static Invoke invokeStaticMethod(String className, String method, Class[] paramTypes, Object[] paramValues)

Here you can find the source of invokeStaticMethod(String className, String method, Class[] paramTypes, Object[] paramValues)

Description

invoke a static method on a class.

License

Open Source License

Parameter

Parameter Description
className a parameter
method a parameter
paramTypes a parameter
paramValues a parameter

Exception

Parameter Description
ClassNotFoundException an exception
NoSuchMethodException an exception
IllegalAccessException an exception
InvocationTargetException an exception

Declaration

public static Object invokeStaticMethod(String className, String method, Class[] paramTypes,
        Object[] paramValues) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException,
        InvocationTargetException 

Method Source Code


//package com.java2s;
import java.lang.reflect.*;

public class Main {
    /**//w w  w  .j a  v  a 2 s.  c  om
     * invoke a static method on a class.
     *
     * @param className
     * @param method
     * @param paramTypes
     * @param paramValues
     * @return
     * @throws ClassNotFoundException
     * @throws NoSuchMethodException
     * @throws IllegalAccessException
     * @throws InvocationTargetException
     */
    public static Object invokeStaticMethod(String className, String method, Class[] paramTypes,
            Object[] paramValues) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException,
            InvocationTargetException {
        Class clz = Class.forName(className);
        Method m = clz.getDeclaredMethod(method, paramTypes);
        return m.invoke(null, paramValues);
    }
}

Related

  1. invokeStaticMethod(Class pClass, String pMethod, Object pParam)
  2. invokeStaticMethod(final Class cls, final String methodName)
  3. invokeStaticMethod(final Class cls, final String methodName, final boolean throwException)
  4. invokeStaticMethod(final Class clazz, final String methodName, final Class[] parameterTypes, final Object[] arglist)
  5. invokeStaticMethod(final Method method, final Object... args)
  6. invokeStaticMethod(String className, String methodName)
  7. invokeStaticMethod(String className, String methodName, Object[] args)
  8. invokeStaticMethodNoArgs(Class clazz, String methodName)