Sasha
Sasha

Reputation: 3281

what exactly does a generic extending from a class mean?

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!

Upvotes: 3

Views: 279

Answers (1)

Mac
Mac

Reputation: 1642

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.

Upvotes: 6

Related Questions