src/main/java/com/github/gquintana/metrics/sql/Driver.java
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);
        }
    }
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);
        }
    }
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

@param clazz  Object class
@param params Constructor args
@param <T>    Object type
@return New object
Instantiate a new object of type T