TypeResolver.java 文件源码

java
阅读 46 收藏 0 点赞 0 评论 0

项目:guava-mock 作者:
private WildcardCapturer forTypeVariable(final TypeVariable<?> typeParam) {
  return new WildcardCapturer(id) {
    @Override TypeVariable<?> captureAsTypeVariable(Type[] upperBounds) {
      Set<Type> combined = new LinkedHashSet<>(asList(upperBounds));
      // Since this is an artifically generated type variable, we don't bother checking
      // subtyping between declared type bound and actual type bound. So it's possible that we
      // may generate something like <capture#1-of ? extends Foo&SubFoo>.
      // Checking subtype between declared and actual type bounds
      // adds recursive isSubtypeOf() call and feels complicated.
      // There is no contract one way or another as long as isSubtypeOf() works as expected.
      combined.addAll(asList(typeParam.getBounds()));
      if (combined.size() > 1) { // Object is implicit and only useful if it's the only bound.
        combined.remove(Object.class);
      }
      return super.captureAsTypeVariable(combined.toArray(new Type[0]));
    }
  };
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号