typeVar.getBounds()
是什么
获取泛型参数的限制范围
简单例子
class Box<T extends Number> { }
// T 被限制为 Number 或它的子类
TypeVariable<?> typeVar = Box.class.getTypeParameters()[0];
Type[] bounds = typeVar.getBounds(); // 返回 [Number.class]
class Container<T extends Comparable & Serializable> { }
// T 必须同时实现 Comparable 和 Serializable
Type[] bounds = typeVar.getBounds();
// 返回 [Comparable.class, Serializable.class]
无限制的情况
class SimpleBox<T> { } // T 没有限制
Type[] bounds = typeVar.getBounds();
// 默认返回 [Object.class]
一句话理解
获取泛型参数T允许的类型范围
67

被折叠的 条评论
为什么被折叠?



