Java Reflection Constructor Invoke invokePrivateConstructor(Class clazz)

Here you can find the source of invokePrivateConstructor(Class clazz)

Description

invoke Private Constructor

License

Apache License

Declaration

public static <T> void invokePrivateConstructor(Class<T> clazz) throws NoSuchMethodException,
            InstantiationException, IllegalAccessException, InvocationTargetException 

Method Source Code


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

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Main {
    public static <T> void invokePrivateConstructor(Class<T> clazz) throws NoSuchMethodException,
            InstantiationException, IllegalAccessException, InvocationTargetException {
        final Constructor<T> constructor = clazz.getDeclaredConstructor();
        constructor.setAccessible(true);
        constructor.newInstance();//  w w  w.j ava 2s  .  co  m
    }
}

Related

  1. invokeConstructorOrFail(Constructor constructor, Object... args)
  2. invokeCtor(Constructor ctor, String str)
  3. invokeExactConstructor(Class klass, Object arg)
  4. invokePrivateConstructor(Class clazz)
  5. invokePrivateConstructor(Class classType)
  6. invokeReflectConstruct(String className, Object[] parameter, Class[] args)