Yep - go with Collection<Object> rather than Collection<?>. For those new to generics, if you're using ?, you're 90% likely to be doing something wrong (if you have to use ?, you're really likely to be overcomplicating generics where other tools like covariant return types from multiple classes will do and be simpler).

Also, another gotcha - if you're working in eclipse, and using it to validate your generics, remember that it is more permissive (in a "you should be able to do this" way), and you can get caught out on a command line javac compile.

Jess Holle wrote:
You can always get the current unchecked behavior with Collection<Object>.

The way Java 5's type erasure works allows generic collections to keep working in all the old code that used the non-genericized versions of these collections. Where one can find a way to do the erasure properly to maintain compatibility with older callers it is a thing of beauty.

--
Jess Holle

Bryce L Nordgren wrote:
Hey all,

This may be something so simple it goes without saying, but it also may be
something that's easy to overlook.

The main value of commons collections is that it performs "intuitive" type
checking.  Collections can contain mixed types which are bounded on both
the top and the bottom end.  They can also be forced to contain only one
type of object. This allieviates some of the practical problems with Java5
collections; namely you can't add anything to a Collection<? extends
Object>.

If you intend to retain this functionality, I believe the only legal way is to retain implementations of Collection (no generics). I would very much
like to see this functionality retained. :)

Please pardon me if this was an "obvious" email.

Bryce


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to