Java Reflection Constructor Invoke invokeReflectConstruct(String className, Object[] parameter, Class[] args)

Here you can find the source of invokeReflectConstruct(String className, Object[] parameter, Class[] args)

Description

invoke Reflect Construct

License

Apache License

Declaration

public static Object invokeReflectConstruct(String className,
            Object[] parameter, Class[] args) 

Method Source Code

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

import java.lang.reflect.Constructor;

public class Main {
    public static boolean isThrowable = true;

    public static Object invokeReflectConstruct(String className,
            Object[] parameter, Class[] args) {
        try {//from  ww w  .  j  a  va  2  s .c  om
            Class clazz = Class.forName(className);
            Constructor constructor = clazz.getDeclaredConstructor(args);
            constructor.setAccessible(true);
            return constructor.newInstance(parameter);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (isThrowable) {
            throw new RuntimeException("invokeReflectConstruct error "
                    + className + "   parameter   " + parameter);
        }
        return null;
    }
}

Related

  1. invokeCtor(Constructor ctor, String str)
  2. invokeExactConstructor(Class klass, Object arg)
  3. invokePrivateConstructor(Class clazz)
  4. invokePrivateConstructor(Class classType)
  5. invokePrivateConstructor(Class clazz)