Java Class New Instance newInstance(Class klass)

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

Description

new Instance

License

Open Source License

Declaration

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

Method Source Code

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

import java.lang.reflect.Constructor;

public class Main {
    public static <T> T newInstance(Class<T> klass) {
        T t = null;/*from  w  w  w .j  a  v a  2 s . com*/
        try {
            Constructor<T> constructor = klass.getDeclaredConstructor();
            if (constructor != null) {
                constructor.setAccessible(true);
                t = constructor.newInstance();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return t;
    }
}

Related

  1. newInstance(Class cls)
  2. newInstance(Class cls, Object... args)
  3. newInstance(Class clz, Class argType, K arg)
  4. newInstance(Class componentType, int size)
  5. newInstance(Class elementType, int len)
  6. newInstance(Class klass)
  7. newInstance(Class klass)
  8. newInstance(Class klass)
  9. newInstance(Class klass, Class[] paramTypes, Object... params)