Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.lang.reflect.Method;

public class Main {
    static public Object invokeStaticMethod(Class<?> claxx, String methodName, Object... args) throws Exception {
        Class<?>[] argsClass = null;

        if (args != null && args.length > 0) {
            argsClass = new Class<?>[args.length];

            for (int i = 0, j = args.length; i < j; i++) {
                argsClass[i] = args[i].getClass();
                if (argsClass[i] == Integer.class) {
                    argsClass[i] = int.class;
                } else if (argsClass[i] == Boolean.class) {
                    argsClass[i] = boolean.class;
                }
            }
        }

        Method method = claxx.getDeclaredMethod(methodName, argsClass);
        method.setAccessible(true);
        return method.invoke(null, args);
    }
}