Java Reflection Method Static Invoke invokeStatic(String cname, String methodName, ClassLoader cl)

Here you can find the source of invokeStatic(String cname, String methodName, ClassLoader cl)

Description

invoke Static

License

Open Source License

Declaration

public static Object invokeStatic(String cname, String methodName, ClassLoader cl) 

Method Source Code

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

import java.lang.reflect.Method;

public class Main {
    private static final Class<?>[] EmptyClassArray = new Class<?>[0];
    private static final Object[] EmptyObjectArray = new Object[0];

    public static Object invokeStatic(String cname, String methodName, ClassLoader cl) {
        return invokeStatic(cname, methodName, cl, EmptyClassArray, EmptyObjectArray);
    }//from ww  w  .ja  v a  2 s  .c om

    public static Object invokeStatic(String className, String methodName, ClassLoader cl, Class<?>[] paramTypes,
            Object... params) {
        try {
            Class<?> c = getClass(className, cl);
            Method m = c.getDeclaredMethod(methodName, paramTypes);
            return m.invoke(null, params);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static <V> Class<V> getClass(String className, ClassLoader cl) throws ClassNotFoundException {
        return (Class<V>) Class.forName(className, true, cl);
    }

    public static <V> Class<V> getClass(String className) throws ClassNotFoundException {
        return (Class<V>) Class.forName(className);
    }
}

Related

  1. invokeReflectStaticMethod(String methodName, Class cl, Object[] parameter, Class[] args)
  2. invokeStatic(Class clazz, String methodName, Class returnClass, Object... args)
  3. invokeStatic(final Class clazz, final String methodName, final Class[] argTypes, final Object[] args)
  4. invokeStatic(final ClassLoader loader, final String className, final String methodName, final Object... parameters)
  5. invokeStatic(final String className, final String methodName, final I argument)
  6. invokeStaticClass(Class staticClass, String methodName, Object[] args, Class... parameterTypes)
  7. invokeStaticMethod(Class objClass, String methodName, Object args[])
  8. invokeStaticMethod(Class cls, String method, Class[] params, Object... args)
  9. invokeStaticMethod(Class cls, String methodName, Object... args)