@ SuppressWarnings ( { "unchecked" , "all" } ) public static < T > Constructor < T > findConstructor ( Class < T > type , Object ... arguments ) { for ( Constructor < ? > constructor : type . getDeclaredConstructors ( ) ) { Class < ? > [ ] parameterTypes = constructor . getParameterTypes ( ) ; if ( ArrayUtils . nullSafeLength ( arguments ) == parameterTypes . length ) { boolean match = true ; for ( int index = 0 ; match && index < parameterTypes . length ; index ++ ) { match &= instanceOf ( arguments [ index ] , parameterTypes [ index ] ) ; } if ( match ) { return ( Constructor < T > ) constructor ; } } } return null ; }
Attempts to find a compatible constructor on the given class type with a signature having parameter types satisfying the specified arguments .