@ SuppressWarnings ( "unchecked" ) public static < T > Constructor < T > getCompatibleConstructor ( Class < T > type , Class < ? > ... paramTypes ) throws NoSuchMethodException { Check . notNull ( type ) ; Check . notNull ( paramTypes ) ; for ( final Constructor < ? > current : type . getDeclaredConstructors ( ) ) { final Class < ? > [ ] constructorTypes = current . getParameterTypes ( ) ; if ( constructorTypes . length == paramTypes . length && ( paramTypes . length == 0 || hasCompatibleConstructor ( paramTypes , constructorTypes ) ) ) { return ( Constructor < T > ) current ; } } throw new NoSuchMethodException ( ERROR_NO_CONSTRUCTOR_COMPATIBLE + type . getName ( ) + ERROR_WITH + Arrays . asList ( paramTypes ) ) ; }
Get a compatible constructor with the following parameters .