private static < T > T newInstance ( Class < T > clazz , Object ... params ) throws SQLException { try { if ( params == null || params . length == 0 ) { return clazz . newInstance ( ) ; } else { for ( Constructor < ? > ctor : clazz . getConstructors ( ) ) { if ( ctor . getParameterTypes ( ) . length != params . length ) { continue ; } int paramIndex = 0 ; for ( Class < ? > paramType : ctor . getParameterTypes ( ) ) { if ( ! paramType . isInstance ( params [ paramIndex ] ) ) { break ; } paramIndex ++ ; } if ( paramIndex != params . length ) { continue ; } @ SuppressWarnings ( "unchecked" ) Constructor < T > theCtor = ( Constructor < T > ) ctor ; return theCtor . newInstance ( params ) ; } throw new SQLException ( "Constructor not found for " + clazz ) ; } } catch ( ReflectiveOperationException reflectiveOperationException ) { throw new SQLException ( reflectiveOperationException ) ; } }
Instantiate a new object of type T