Java Class New Instance newInstance(Class cl)

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

Description

Create a new instance of a class

License

Open Source License

Parameter

Parameter Description
cl The class object.
T The class type.

Return

New class instance.

Declaration

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

Method Source Code

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

public class Main {
    /**//from w w  w .  j a v a2 s  .  c o  m
     * Create a new instance of a class
     *
     * @param cl The class object.
     * @param <T> The class type.
     * @return New class instance.
     */
    public static <T> T newInstance(Class<T> cl) {
        try {
            return cl.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. newInstance(Class arrayComponentClass, T value)
  2. newInstance(Class beanClass)
  3. newInstance(Class c)
  4. newInstance(Class c)
  5. newInstance(Class c, Class[] argTypes, Object[] args)
  6. newInstance(Class classOf)
  7. newInstance(Class clazz)
  8. newInstance(Class clazz)
  9. newInstance(Class clazz)