commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryce L Nordgren <bnordg...@fs.fed.us>
Subject Re: [collections] VOTE: Collections-java5 direction
Date Mon, 12 Mar 2007 19:55:54 GMT


Jess Holle <jessh@ptc.com> wrote on 03/12/2007 12:28:34 PM:

> You can always get the current unchecked behavior with
Collection<Object>.

Thing 1:
========
Ummm.  The fact that the above statement is incorrect is precisely why
Java5 generics syntax is dangerous.  Collection<Object> is not considered a
supertype of any other typed Collection, and is therefore not
interchangeable with other typed collections.  (e.g. you can't pass it
around like you would a Collection)

To treat the elements of the collection as you always have, one needs
Collection<Object>, as above.
To treat the collections themselves as you always have, one needs
Collection<?>.

However, if you have a collection which is a supertype of all other
collections, you cannot add any elements to it because the single legal
element type for that collection is unknown.

Thing 2:
========
I don't want the old unchecked behavior.  I want checked behavior,
commons-collections style.  Commons-collections can handle mixed element
types, where every element has bounds on its types.  Generics do not even
contain a way to express "this collection is potentially composed of a
mixture of elements, but every element is guaranteed to be between {Parent}
and {Child} in the class hierarchy".  In order to implement this type of
checked behavior, Java Generics requires that we use the "unchecked"
syntax.  I guess we should call it "implementation-defined type checking".
My plea is not intended to start a war over Java generics, but to beg that
current functionality not be abandonded merely because Java Generics cannot
adequately describe it.

Thing 3:
========
:)

Bryce


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message