commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael A. Smith" <>
Subject Re: [collection] Collections for primitives
Date Sat, 22 Jun 2002 20:56:58 GMT
On Sat, 22 Jun 2002, Ola Berg wrote:

> The collections for primitves has dangerous behaviour in the methods
> where you recieve an Object as an argument, where it just tries to
> cast the argument to an Integer (or Float etc). This will result in a
> ClassCastException, which could be appropriate somtimes, but not in
> all cases.
> Shouldn\'t myIntList.contains( \"Foo\") result in false?

No.  The Collection.contains(Object) contract declares that a 
ClassCastException is thrown "if the type of the specified element is 
incompatible with this collection".  "Foo" is incompatible with an int 

This is not alted in the List contract.

> Shouldn\'t myIntList.[lastI | i]ndexOf( \"Foo\") result in -1?

No.  Same reasons as above.
> Shouldn\'t myIntList.add( \"Foo\") result in false, indicating that
> the object couldn\'t be added?

No. Same reason as above.

> And so on (remove() etc)?

No. Same reason as above.

> Should I fix this and send a patch to someone, or is it the desired
> behaviour? If it is desired, I could make javadoc comments about it
> instead.

The throwing of a ClassCastException may not seem "appropriate", but it 
is already documented in the Collection contract (and also the List 
contract and Map contract).  There is no reason to "fix" it because it 
follows the contract.  Added documentation restating the documentation 
in Collection and List is doable, but not necessary in my opinion.


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message