コード例 #1
0
 /**
  * More efficient version of {@link #narrowBy}, called by internal framework in cases where
  * compatibility checks are to be skipped.
  *
  * @since 1.5
  */
 public JavaType forcedNarrowBy(Class<?> subclass) {
   if (subclass == _class) { // can still optimize for simple case
     return this;
   }
   JavaType result = _narrow(subclass);
   // TODO: these checks should NOT actually be needed; above should suffice:
   if (_valueHandler != result.getValueHandler()) {
     result = result.withValueHandler(_valueHandler);
   }
   if (_typeHandler != result.getTypeHandler()) {
     result = result.withTypeHandler(_typeHandler);
   }
   return result;
 }
コード例 #2
0
  /**
   * Method that can be called to do a "narrowing" conversions; that is, to return a type with a raw
   * class that is assignable to the raw class of this type. If this is not possible, an {@link
   * IllegalArgumentException} is thrown. If class is same as the current raw class, instance itself
   * is returned.
   */
  public JavaType narrowBy(Class<?> subclass) {
    // First: if same raw class, just return this instance
    if (subclass == _class) {
      return this;
    }
    // Otherwise, ensure compatibility
    _assertSubclass(subclass, _class);
    JavaType result = _narrow(subclass);

    // TODO: these checks should NOT actually be needed; above should suffice:
    if (_valueHandler != result.getValueHandler()) {
      result = result.withValueHandler(_valueHandler);
    }
    if (_typeHandler != result.getTypeHandler()) {
      result = result.withTypeHandler(_typeHandler);
    }
    return result;
  }