@ SuppressWarnings ( "unchecked" ) private static < T > Constructor < T > getPotentialVarArgsConstructor ( Class < T > classThatContainsTheConstructorToTest , Object ... arguments ) { Constructor < T > [ ] declaredConstructors = ( Constructor < T > [ ] ) classThatContainsTheConstructorToTest . getDeclaredConstructors ( ) ; for ( Constructor < T > possibleVarArgsConstructor : declaredConstructors ) { if ( possibleVarArgsConstructor . isVarArgs ( ) ) { if ( arguments == null || arguments . length == 0 ) { return possibleVarArgsConstructor ; } else { Class < ? > [ ] parameterTypes = possibleVarArgsConstructor . getParameterTypes ( ) ; if ( parameterTypes [ parameterTypes . length - 1 ] . getComponentType ( ) . isAssignableFrom ( getType ( arguments [ 0 ] ) ) ) { return possibleVarArgsConstructor ; } } } } return null ; }
Gets the potential var args constructor .