Java Utililty Methods Reflection Constructor Invoke

List of utility methods to do Reflection Constructor Invoke

Description

The list of methods to do Reflection Constructor Invoke are organized into topic(s).

Method

ObjectinvokePrivateConstructor(Class clazz)
Utility method for Unit tests to invoke private constructors
Constructor<?> constructor = null;
try {
    constructor = clazz.getDeclaredConstructor();
} catch (NoSuchMethodException e) {
    System.err.println("Constructor for [" + clazz.getName() + "] does not exist");
constructor.setAccessible(true);
Object instance = null;
...
voidinvokePrivateConstructor(Class classType)
invoke Private Constructor
Constructor<E> constructor = classType.getDeclaredConstructor();
constructor.setAccessible(true);
constructor.newInstance();
voidinvokePrivateConstructor(Class clazz)
invoke Private Constructor
final Constructor<T> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
constructor.newInstance();
ObjectinvokeReflectConstruct(String className, Object[] parameter, Class[] args)
invoke Reflect Construct
try {
    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;