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.
精彩评论