public static Class < ? > [ ] getConstructorParameters ( Class < ? > type , Class < ? > [ ] givenTypes ) { next_constructor : for ( Constructor < ? > constructor : type . getConstructors ( ) ) { int matches = 0 ; Class < ? > [ ] parameters = constructor . getParameterTypes ( ) ; Iterator < Class < ? > > parameterIterator = Arrays . asList ( parameters ) . iterator ( ) ; if ( ! isEmpty ( givenTypes ) && ! isEmpty ( parameters ) ) { Class < ? > parameter = null ; for ( Class < ? > argument : givenTypes ) { if ( parameterIterator . hasNext ( ) ) { parameter = parameterIterator . next ( ) ; if ( ! compatible ( parameter , argument ) ) { continue next_constructor ; } matches ++ ; } else if ( constructor . isVarArgs ( ) ) { if ( ! compatible ( parameter , argument ) ) { continue next_constructor ; } } else { continue next_constructor ; //default } } if ( matches == parameters . length ) { return parameters ; } } else if ( isEmpty ( givenTypes ) && isEmpty ( parameters ) ) { return NO_ARGS ; } } throw new ExpressionException ( "No constructor found for " + type . toString ( ) + " with parameters: " + Arrays . deepToString ( givenTypes ) ) ; }
Returns the parameters for the constructor that matches the given types .