Planned extension methods in Iterable and subtypes thereof
Brian Goetz
brian.goetz at oracle.com
Sat Mar 3 07:40:26 PST 2012
The specifics of the library improvements are still at an early point.
We're converging on the main design concepts, but how they connect to
collections, what we call them, etc, are all still in flight.
On 3/3/2012 8:10 AM, Lukas Eder wrote:
> Hello,
>
> I am referring to page 55 of this presentation that I have found on the web:
> https://blogs.oracle.com/briangoetz/resource/devoxx-lang-lib-vm-co-evol.pdf
>
> It depicts the possible evolution of the Iterable interface using
> extension methods that are very convenient for the whole collections
> API:
>
> ------------------------------------------------------------
> public interface Iterable<T> {
> Iterator<T> iterator();
> boolean isEmpty() default ...;
> void forEach(Block<? super T> block) default ...;
> Iterable<T> filter(Predicate<? super T> predicate) default ...;
> <U> Iterable<U> map(Mapper<? super T, ? extends U> mapper) default ...;
> T reduce(T base, Operator<T> reducer) default ...;
> Iterable<T> sorted(Comparator<? super T> comp) default ...;
> <C extends Collection<? super T>>
> C into(C collection) default ...;
> // and more...
> }
> ------------------------------------------------------------
>
> Are these ideas around the Iterable interface formally stabilising?
> I'm asking because I'd like to add similar methods in my proprietary
> List extension:
>
> ------------------------------------------------------------
> public interface Result<R> extends List<R> {
> Result<R> sorted(Comparator<? super R> comp);
> Result<R> filter(MyPredicate<? super R> predicate);
> // ...
> }
> ------------------------------------------------------------
>
> When adding such features to my Result type, I'd like to stay as close
> as possible to what will be available in Java 8, such that migrating
> this API will be simple ("sorted()" overrides the inherited version as
> it is, "filter()" will be overloaded by the inherited extension
> method, my own version deprecated). So are these ideas already stable?
> Or is Java 8's collections API evolution still an open point?
>
> Cheers
> Lukas
>
More information about the lambda-dev
mailing list