从类扩展的泛型到底意味着什么?
这究竟意味着什么?
public class Deck<T extends Card>
T扩展卡是什么意思?这是否暗示了卡类的某些内容?
谢谢!
what does this exactly mean?
public class Deck<T extends Card>
What does the T extends Card mean? Does this imply something about the class Card?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它将类型参数(“T”)限制为
Card
或Card
的子类型。因此,如果
...那么它是与
Deck
一起使用的有效类型(即Deck
)。但是,String
显然不扩展Card
,因此Deck
将无法编译。It constrains the type parameter ("T") to be
Card
or a subtype ofCard
.So if
... then it is a valid type for use with
Deck
(i.e.Deck<FancyCard>
). However,String
obviously does not extendCard
, soDeck<String>
will not compile.