Java Reflection Method Static Invoke invokeStaticMethod(String className, String methodName, Object[] args)

Here you can find the source of invokeStaticMethod(String className, String methodName, Object[] args)

Description

invoke Static Method

License

Open Source License

Declaration

public static Object invokeStaticMethod(String className, String methodName, Object[] args) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Method;

public class Main {

    public static Object invokeStaticMethod(String className, String methodName, Object[] args) throws Exception {
        Class ownerClass = Class.forName(className);
        Class[] argsClass = new Class[args.length];

        for (int i = 0, j = args.length; i < j; i++) {
            argsClass[i] = args[i].getClass();
        }/* ww w  .j  a  v a2  s. co  m*/

        Method method = ownerClass.getMethod(methodName, argsClass);
        return method.invoke(null, args);
    }
}

Related

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