More Readable Use Site extension Methods for java
Ali Ebrahimi
ali.ebrahimi1781 at gmail.com
Sun Dec 5 22:51:28 PST 2010
I propose to have use site and declaration site extension methods.
declaration site extension methods by Brian Defender Methods and use
site extension methods as following:
import static MyUtils.select extends java.util.List;
import static MyUtils.sortby extends java.util.List;
...
List<Foo> myList=getList();
List newList =myList.select(#{f -> f.isReal()}).sortby(F#getName());
And
class MyUtils{
public <T> static List<T> select(List<T> list, Predicate<T> p);
public <T> static List<T> sortby(List<T> list, Sorter<T> p);
}
interface Sorter<T>{
Comparable<?> apply(T t);
}
This an enhanced version of previously proposed use site extension methods.
import statement can be in package level (package-info.java ) and even in
module level (module-info.java ).
this is for those prefer use site extension methods.
This is just an suggestion. I fully support current defender methods. In
current method, API consumers don't have control over them unless subclass
them.
I suggest java to support both use site and declaration site extension
methods.
Best Regards
Ali Ebrahimi
More information about the lambda-dev
mailing list