从类扩展的泛型到底意味着什么?

发布于 2024-12-07 21:02:57 字数 129 浏览 5 评论 0原文

这究竟意味着什么?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

べ繥欢鉨o。 2024-12-14 21:02:57

它将类型参数(“T”)限制为 CardCard 的子类型。

因此,如果

public class FancyCard extends Card

...那么它是与 Deck 一起使用的有效类型(即 Deck)。但是,String 显然不扩展 Card,因此 Deck 将无法编译。

It constrains the type parameter ("T") to be Card or a subtype of Card.

So if

public class FancyCard extends Card

... then it is a valid type for use with Deck (i.e. Deck<FancyCard>). However, String obviously does not extend Card, so Deck<String> will not compile.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文