<?> is appropriate.
Unless you want to parameterize the method. But otherwise, yes, <?> is the right choice. List<Object> says it's a list of objects. It can only be assigned to a to list of objects.
List<?> says it's a list of something, but you don't know what.
Those are two slightly different statements.
For example:

List<Object> foo1 = new ArrayList<Object>(); //legal
List<?> foo2 = new ArrayList<Object>(); //also legal.
List<Object> foo3 = new ArrayList<Persistent>(); //illegal; you'll get a compile-time error.
List<?> foo4 = new ArrayList<Persistent>();//this is legal.

other comments...
foo1.add(somePersistentObject); will be legal.
foo4.add(somePersistentObject) will NOT be legal, because foo4 is of wildctionard.

The other option, as i mentioned, is to parameterize your method...

public <T> List<T> getSomeCollection() { }

Or even
public <T extends Persistent> List<T> getSomeCollection();

Robert

On Nov 18, 2007, at 11/189:08 AM , Andrus Adamchik wrote:

Didn't find an answer for this particular case in the articles below (although they were informative otherwise)... Looking at the JDK's own classes, I see a few of "Collection<?> getSomething()" methods in various places.

Andrus


On Nov 16, 2007, at 7:34 PM, Aristedes Maniatis wrote:


On 17/11/2007, at 11:19 AM, Andrus Adamchik wrote:

I have no idea. I am just overwhelmed with millions of Eclipse warnings :-)

Anyone else has a reference?

Andrus


I found these articles the best for tips and tricks when I was first working on generics:

http://www.onjava.com/pub/a/onjava/excerpt/javaian5_chap04/index.html
http://www.ibm.com/developerworks/java/library/j-jtp01255.html


Ari


-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A





Reply via email to