Noob question: how to create generic object holding multiple types
Hi,
I have been working through the sun tutorials, and I am having some difficulty getting the hang of generics...
The tutorial's excercise suggests the following class to function as a library for books, videos and newspapers:
--
import java.util.List;
import java.util.ArrayList;
public class Library<E extends Media> {
private List<E> resources = new ArrayList<E>();
public void addMedia(E x) {
resources.add(x);
}
public E retrieveLast() {
int size = resources.size();
if (size > 0) {
return resources.get(size - 1);
}
return null;
}
}
--
If I want to create an instance of this class that will allow books, videos or newspapers to be added, how should the class be instaniated?
I have tried:
Library<? extends Media> testLibrary = new Library<? extends Media>();
The tutorial isn't very clear on how to go about doing this. Any help is appreciated!

