commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael A. Smith" <...@apache.org>
Subject Re: [collection] Collections for primitives
Date Tue, 25 Jun 2002 18:43:25 GMT
On Tue, 25 Jun 2002, Stephen Colebourne wrote:
> From: "Michael A. Smith" <mas@apache.org>
> > > Hm.  Based on what I've just said, it might be defensible for the
> > > Predicate and primitive collections to remain as they are.  For
> > > the primitive case, it's always exceptional to pass in a non-primitive;
> > > but for the predicate case, it may or may not be exceptional to pass
> > > in a value that fails the predicate.  Hence the different behaviors.
> >
> > my point exactly.  :)
> 
> I just find this pesky. My use case revolves around me not knowing that its
> a primitive collection that I'm querying.

And I'm looking for a real-world case where that would actually be true 
and correct.

> List list = new IntArrayList();
> list.add(7);
> if (checkForFriendlyLists(list)) {
>   // do something
> }
> 
> public boolean checkForFriendlyLists(List list) {
>     return list.contains("Hello!");
> }
> 
> This is very contrived, I know. But the point is that the second method
> might not have been written by you. Its not going to be expecting a
> ClassCastException, and thus might not handle it.

If you are implementing a library of some sort that accepts a List as an
argument without knowing whether there are object eligibility
restrictions (checkForFriendlyLists), you'd have to abide by the List
contract completely and expect ClassCastExceptions.  So you're shifting 
the bug.  Why would that library assume it knows what is allowed in the 
collection when the List contract clearly states that some Lists don't 
allow any Object to be passed into its methods as arguments.  

regards,
michael


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


Mime
View raw message