开发者

what exactly does a generic extending from a class mean?

开发者 https://www.devze.com 2023-04-11 09:07 出处:网络
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?

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

精彩评论

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