Java Class New Instance newInstance(Class clazz)

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

Description

new Instance

License

Open Source License

Declaration

static public <T> T newInstance(Class<T> clazz) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Constructor;

public class Main {
    static public <T> T newInstance(Class<T> clazz) {
        Constructor<T> ctor = null;
        try {//  w w w  . j  a va  2  s  .co m
            ctor = clazz.getDeclaredConstructor(new Class<?>[0]);
            ctor.setAccessible(true);
            T o = ctor.newInstance(new Object[0]);
            return o;
        } catch (Throwable t) {
            return null;
        } finally {
            if (ctor != null) {
                ctor.setAccessible(false);
            }
        }
    }
}

Related

  1. newInstance(Class clazz)
  2. newInstance(Class clazz)
  3. newInstance(Class clazz)
  4. newInstance(Class clazz)
  5. newInstance(Class clazz)
  6. newInstance(Class clazz, Class[] argumentTypes, Object[] arguments)
  7. newInstance(Class clazz, Class[] parameterTypes, Object[] initargs)
  8. newInstance(Class cls)
  9. newInstance(Class cls)