? extends CLASS
import java.util.ArrayList;
publicclass Driver
{
private ArrayList<?extends String> list =null;// WORKS
private ArrayList<?implements Comparable> list =null;// ! WORK
}
How can I get the second line to work. I would this ArrayList to store anything that implements the Comparable interface.
Thanx
> How can I get the second line to work. I would this
> ArrayList to store anything that implements the
> Comparable interface.
As eaaje said above, in this situation, you use extends, not implements. This was a decision of those that extended java to be able to use generics. Just go with extends. It should work just fine.
Here's a great generics tutorial:
http://java.sun.com/docs/books/tutorial/extra/generics/index.html
and another...
http://java.sun.com/developer/technicalArticles/J2SE/generics/index.html
Message was edited by:
petes1234