Design for collections upgrades

Alessio Stalla alessiostalla at gmail.com
Thu Mar 10 03:32:45 PST 2011


On Thu, Mar 10, 2011 at 12:04 PM, Rémi Forax <forax at univ-mlv.fr> wrote:
>  Le 10/03/2011 11:46, "Zdeněk Troníček" a écrit :
>> To me it seems logical that filter() returns the same collection as was
>> the original collection. For Set you do not have any other choice either:
>>
>> set.filter(predicate)
>>
>> cannot switch from HashSet to TreeSet or back.
>>
>> Z.
>
> How do you implement that ?

Well, extension methods are polymorphic, is that right? Then, you
could have a different extension method per Set implementation, and a
default one for Set that uses HashSet. If such an extension method
existed, it should not be tied to filter in particular; I'm thinking
of a generic newInstance() method. It could in fact be generalized for
Collection.

Alessio


More information about the lambda-dev mailing list