@ SuppressWarnings ( "unchecked" ) public static < T > T newInstance ( final Class < T > clazz , final Object ... params ) throws InstantiationException , IllegalAccessException , InvocationTargetException , NoSuchMethodException { if ( params . length == 0 ) { return newInstance ( clazz ) ; } final Class < ? > [ ] paramTypes = getClasses ( params ) ; final Constructor < ? > constructor = findConstructor ( clazz , paramTypes ) ; if ( constructor == null ) { throw new InstantiationException ( "No constructor matched parameter types." ) ; } return ( T ) constructor . newInstance ( params ) ; }
Creates new instance of given class with given optional arguments .