Java Reflection Method Static Invoke invokeStaticClass(Class staticClass, String methodName, Object[] args, Class... parameterTypes)

Here you can find the source of invokeStaticClass(Class staticClass, String methodName, Object[] args, Class... parameterTypes)

Description

invoke Static Class

License

Apache License

Declaration

public static Object invokeStaticClass(Class<?> staticClass, String methodName, Object[] args,
            Class... parameterTypes) 

Method Source Code

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

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
    private static Logger log = LoggerFactory.getLogger("org.featureflags.Utils");

    public static Object invokeStaticClass(Class<?> staticClass, String methodName, Object[] args,
            Class... parameterTypes) {
        Method method = null;/*from   w w  w . ja  v  a 2 s .com*/
        try {
            method = staticClass.getMethod(methodName, parameterTypes);
        } catch (SecurityException e) {
            log.error("Can't get method " + methodName, e);
            return null;
        } catch (NoSuchMethodException e) {
            log.error("Can't get method " + methodName, e);
            return null;
        }

        try {
            return method.invoke(null, args);
        } catch (IllegalArgumentException e) {
            log.error("Can't call method " + methodName, e);
        } catch (IllegalAccessException e) {
            log.error("Can't call method " + methodName, e);
        } catch (InvocationTargetException e) {
            if (e.getTargetException() instanceof IllegalArgumentException) {
                log.info("Flag does not exist " + args[0]);
            } else {
                log.error("Can't call method " + methodName, e);
            }
        }

        return null;
    }
}

Related

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