? 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

[770 byte] By [java4life87a] at [2007-11-27 10:37:59]
# 1

with wildcard you always sayed extends

eaajea at 2007-7-28 18:51:41 > top of Java-index,Java Essentials,Java Programming...
# 2

> 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

petes1234a at 2007-7-28 18:51:41 > top of Java-index,Java Essentials,Java Programming...