Here you can find the source of newInstance(Class
Parameter | Description |
---|---|
T | the generic type |
sourceClass | the source class |
public static <T> T newInstance(Class<T> sourceClass)
//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); } } }