RFR: 8001647: In-place methods on Collection/List

Stephen Colebourne scolebourne at joda.org
Mon Dec 10 07:52:52 PST 2012


On 10 December 2012 13:28, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> On 08/12/2012 01:42, Akhil Arora wrote:
>> As part of the Library Lambdafication, this patch adds the following
>> default methods to Collections -
>>
>> Iterable.forEach(Block<T>)
>> Collection.removeAll(Predicate<T>)
>> List.sort(Comparator)
>> List.replaceAll(UnaryOperator<T>)
>>
>> It also provides more efficient implementations of these methods for
>> ArrayList, Vector and CopyOnWriteArrayList. Please review.
>>
>> http://cr.openjdk.java.net/~akhil/8001647.1/webrev/
>>
>> Thanks to the many people who have already contributed to this patch.
>>
> This may be bikeshed territory but we usually don't use the "public"
> modifier on methods defined by interfaces as they are public anyway. It
> seems inconsistent to me to have it on the default methods. Perhaps this has
> been discussed before, in which case ignore this. BTW: The only reason I'm
> bringing this up is because there are lots of default methods to come and it
> would be nice to establish a convention and consistency from the start.

I agree that consistency would be good. FWIW, I think there is a case
to use public everywhere now on interfaces, and effectively discourage
use of the "default". This would position the interfaces in a better
place were a new "package" modifier to be added in JDK9 (such as to
allow package scoped methods on interfaces, now they have trait-like
behaviour).

Stephen


More information about the lambda-dev mailing list