Java Class New Instance newInstance(Class sourceClass)

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

Description

New instance of the specified class.

License

LGPL

Parameter

Parameter Description
T the generic type
sourceClass the source class

Return

the created instance using the default constructor

Declaration

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

Method Source Code

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

public class Main {
    /**//  w  w  w . ja  v a 2  s.  c  o m
     * New instance of the specified class.
     *
     * @param <T>
     *            the generic type
     * @param sourceClass
     *            the source class
     * @return the created instance using the default constructor
     */
    public static <T> T newInstance(Class<T> sourceClass) {
        try {
            return sourceClass.newInstance();
        } catch (InstantiationException e) {
            throw new IllegalStateException(e);
        } catch (IllegalAccessException e) {
            throw new IllegalStateException(e);
        }
    }
}

Related

  1. newInstance(Class klass)
  2. newInstance(Class klass)
  3. newInstance(Class klass, Class[] paramTypes, Object... params)
  4. newInstance(Class klass, Object... args)
  5. newInstance(Class listener)
  6. newInstance(Class targetType, String className, ClassLoader loader)
  7. newInstance(Class tClass, Object... initargs)
  8. newInstance(Class theClass)
  9. newInstance(Class theClass)