开发者

what exactly does a generic extending from a class mean?

what does this exactly mean?

public class Deck&l开发者_StackOverflow社区t;T extends Card> 

What does the T extends Card mean? Does this imply something about the class Card?

thanks!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜