Java Class New Instance newInstance(Class c)

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

Description

Instantiate the class

License

Open Source License

Declaration

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

Method Source Code

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

public class Main {
    /**/* ww  w .  j  av  a  2  s  . c om*/
     * Instantiate the class
     */
    public static <T> T newInstance(Class<T> c) {
        try {
            return c.newInstance();
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Could not instantiate class " + c.getName(), e);
        } catch (InstantiationException e) {
            throw new RuntimeException("Could not instantiate class " + c.getName()
                    + " Does it have a public no-argument constructor?", e);
        } catch (NullPointerException e) {
            throw new RuntimeException("Requested class was null", e);
        }
    }
}

Related

  1. newInstance(Class interfaceDefinition, String className, ClassLoader classLoader)
  2. newInstance(Class aClass, Object... args)
  3. newInstance(Class arrayComponentClass, T value)
  4. newInstance(Class beanClass)
  5. newInstance(Class c)
  6. newInstance(Class c, Class[] argTypes, Object[] args)
  7. newInstance(Class cl)
  8. newInstance(Class classOf)
  9. newInstance(Class clazz)