在Java类型参数中,< ;?扩展E>仅意味着严格的亚型?或者E也足够了? [英] In Java type arguments, does <? extends E> mean strictly subtypes only? or would E also suffice?
问题描述
是, super
和 extends
分别给出了包含的上下限。
什么是有界通配符?
通配符的上界看起来像
?类型
类型类型的所有类型的族,表示类型>被包含。
类型
被称为上界。
带有下限的通配符看起来像
?超类型
,代表超类型为类型
,类型类型
被包含。类型
被称为下界。
In Java type arguments, does mean strictly subtypes only? or would E also suffice?
Yes, super
and extends
gives inclusive lower and upper bounds respectively.
Here's a quote from Angelika Langer's Generics FAQ:
What is a bounded wildcard?
A wildcard with an upper bound looks like
? extends Type
and stands for the family of all types that are subtypes ofType
, typeType
being included.Type
is called the upper bound.A wildcard with a lower bound looks like
? super Type
and stands for the family of all types that are supertypes ofType
, typeType
being included.Type
is called the lower bound.
这篇关于在Java类型参数中,< ;?扩展E>仅意味着严格的亚型?或者E也足够了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!