public Constructor < ? > getCompatibleConstructor ( Class < ? > type , Class < ? > argumentType ) { try { return type . getConstructor ( new Class [ ] { argumentType } ) ; } catch ( Exception e ) { // get public classes and interfaces Class < ? > [ ] types = type . getClasses ( ) ; for ( int i = 0 ; i < types . length ; i ++ ) { try { return type . getConstructor ( new Class [ ] { types [ i ] } ) ; } catch ( Exception e1 ) { } } } return null ; }
Get a compatible constructor