Java Reflection Method Static Invoke invokeStaticMethod(Class cls, String methodName, Object... args)

Here you can find the source of invokeStaticMethod(Class cls, String methodName, Object... args)

Description

invoke Static Method

License

Apache License

Declaration

public static Object invokeStaticMethod(Class<?> cls, String methodName, Object... args)
        throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
        InvocationTargetException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {

    public static Object invokeStaticMethod(Class<?> cls, String methodName, Object... args)
            throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
            InvocationTargetException {
        int arguments = args.length;
        Class<?>[] parameterTypes = new Class[arguments];
        for (int i = 0; i < arguments; i++) {
            parameterTypes[i] = args[i].getClass();
        }/*from w w w .j  a va  2s  . c  o  m*/
        Method method = cls.getMethod(methodName, parameterTypes);
        return method.invoke(null, args);
    }
}

Related

  1. invokeStatic(final String className, final String methodName, final I argument)
  2. invokeStatic(String cname, String methodName, ClassLoader cl)
  3. invokeStaticClass(Class staticClass, String methodName, Object[] args, Class... parameterTypes)
  4. invokeStaticMethod(Class objClass, String methodName, Object args[])
  5. invokeStaticMethod(Class cls, String method, Class[] params, Object... args)
  6. invokeStaticMethod(Class cls, String name)
  7. invokeStaticMethod(Class klass, String methodName)
  8. invokeStaticMethod(Class objectType, String name, Class paramTypes[], Object args[])
  9. invokeStaticMethod(Class pClass, String pMethod, Object pParam)