public static Constructor getCompatibleConstructor(final Class type,
                                                      final Class valueType)
   {
      // first try and find a constructor with the exact argument type
      try {
         return type.getConstructor(new Class[] { valueType });
      }
      catch (Exception ignore) {
         // if the above failed, then try and find a constructor with
         // an compatible argument type

         // get an array of compatible types
         Class[] types = type.getClasses();

         for (int i=0; i<types.length; i++) {
            try {
               return type.getConstructor(new Class[] { types[i] });
            }
            catch (Exception ignore2) {}
         }
      }

      // if we get this far, then we can't find a compatible constructor
      return null;
   }
public static Constructor getCompatibleConstructor ( final Class type , final Class valueType ) { try { return type . getConstructor ( new Class [ ] { valueType } ) ; } catch ( Exception ignore ) { Class [ ] types = type . getClasses ( ) ; for ( int i = 0 ; i < types . length ; i ++ ) { try { return type . getConstructor ( new Class [ ] { types [ i ] } ) ; } catch ( Exception ignore2 ) { } } } return null ; }
Get a compatible constructor for the given value type

@param type       Class to look for constructor in
@param valueType  Argument type for constructor
@return           Constructor or null