What you're doing doesn't quite make sense. Do you really want a class Football that is a generic? That is, you could do something like this:
class AmericanFootball extends Sports {
}
class Soccer extends Sports {
}
class Football<T extends Sports> {
}
Football<AmericanFootball> anAmericanFootball;
Football<Soccer> aSoccerBall;
Is that really want you mean:
Or should you have:
class Football extends Sports {
}
And by that you're probably meaning American Football (if you live in the United States) or Soccer (if you live anywhere else in the world). Does your object actually talk about a ball that is either round or, well, shaped like an American football? Or is your class supposed to represent the SPORT of Football?
Let's say you mean:
class Football extends Sports {
}
Collection<Football> myCollection = new ArrayList<Football>();
Football ballOne = new Football();
Football ballTwo = new Football();
myCollection.add(ballOne);
myCollection.add(ballTwo);
Now, to try to answer your REAL question:
Collection<? extends Sports>
Let's start more simply. You can define this:
Collection<?> foo;
What this means is that foo contains objects of unknown type. It's something you can do if you are going to receive a collection of varying objects. Without testing, I believe you could actually receive ANY collection that way, but if you specify it this way:
Collection<Object> foo;
Then you can only assign that literally to a collection of Objects, not any collection. Anyway, doing Collection is what people did when generics first starting letting you specify what is contained, and they had code that was sloppy. It's a bad habit, but worth understanding.
Anyway, I tried this just to be sure I wasn't wrong:
import java.util.Collection;
import java.util.ArrayList;
class Foo {
public void blah() {
Collection<? extends Foo> array = new ArrayList<Foo>();
Collection<? extends Foo> badArray = new ArrayList<Object>();
}
};
And java likes the first ArrayList line and doesn't like the second. The reason is that Foo satisfies but Object does not.
So... To answer the real question, means it can take any collection class that is defined as a collection of Foo or a collection of any subclasses of foo.
means it can take an ArrayList or an ArrayList or an ArrayList but not an ArrayList as Singing probably doesn't subclass from Sports.