I was wondering why we have to use extends
in java generics. For example:
class Team<T extends Player>
And we could have different types of players that inherit from the original Player class:
class FootballPlayer extends Player
class BaseballPlayer extends Player
Why do we have to use <T extends Player>
in the Team
class. Can't we just use Player
?
When we add for example FootballPlayer
to <extends Player>
it works fine, but surely if we added FootballPlayer
to <Player>
, then it would work, because FootballPlayer
is a player? When we do <T extends Player>
, that means that anything we add must inherit from Player
. So why doesn't simply <Player>
work?
Thanks