Planned extension methods in Iterable and subtypes thereof
Lukas Eder
lukas.eder at gmail.com
Sat Mar 3 05:10:33 PST 2012
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