Java Class New Instance newInstance(final Class clazz)

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

Description

new Instance

License

Apache License

Declaration

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

Method Source Code


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

import java.lang.reflect.Constructor;

public class Main {
    public static <T> T newInstance(final Class<T> clazz) {
        try {//from  www  .  j a  v a  2s .  c  o  m
            final Constructor<T> constructor = clazz.getDeclaredConstructor();
            constructor.setAccessible(true);

            return constructor.newInstance();
        } catch (ReflectiveOperationException e) {
            throw new IllegalStateException(e);
        }
    }
}

Related

  1. newInstance(final Class arrayClass, final int length)
  2. newInstance(final Class clazz)
  3. newInstance(final Class clazz)
  4. newInstance(final Class clazz)
  5. newInstance(final Class clazz)
  6. newInstance(final Class type, final int length)
  7. newInstance(final ClassLoader classLoader, final String className, final Object... constructorArgs)
  8. newInstance(final Object obj, final String clazz)
  9. newInstance(final String className, ClassLoader cl)