List of all default methods
Remi Forax
forax at univ-mlv.fr
Thu Nov 21 05:53:12 PST 2013
On 11/21/2013 01:49 PM, Jochen Theodorou wrote:
> Am 21.11.2013 12:59, schrieb Remi Forax:
>> On 11/21/2013 09:48 AM, Jochen Theodorou wrote:
>>> Hi all,
>>>
>>> we already found we have some trouble with List#sort(Comparable) in
>>> Groovy, but to be able to identify further problems it would be very
>>> helpful to have a list of all default methods, that have been added. Is
>>> there one somewhere?
>>
>> Not a beautiful code, it takes rt.jar as argument and do the job :)
> [...]
>
> thanks Remi ;)
>
> from what I can see Groovy has only this one conflict of
> Iterable#sort(Comparable) from us with List#sort(Comparable) from
> jdk8. Is there any rationale behind adding a mutating sort method to
> List by default?
Collections.sort(list) doesn't have access to the underlying array of
the ArrayList so sorting an ArrayList with Collections.sort() is done by
dumping the ArrayList into an array, sorting it and then replacing the
values inside the ArrayList by the one of the intermediary array.
With List.sort(), because a default method can be overridden,
ArrayList.sort() can do the sort on the underlying array directly
without using an intermediary array.
why it's a mutating sort:
All methods on collections that do mutations, do mutation on the current
structure directly so from the API consistency point of view,
List.sort() should be mutable. That's also one of the reason why there
is a Stream API an not a method filter or map directly on Iterable.
>
> bye Jochen
>
regards,
Rémi
More information about the lambda-dev
mailing list