Re:Eclipse launches new language to cut down Java boilerplat...
by linuxhansl on Sunday November 06, 2011 @11:38PM
(#3205003)
With a bit of code:
public interface Functor<T> {
T apply(T v);
}
public class Util {
public static <T> List<T> collect(List<T> l, Functor<T> f) {
List<T> result = new ArrayList<T>();
for (T v : l) {
result.add(f.apply(v));
}
return result;
}
}
You can write:
List<String> l = ...;
Util.collect(l, new Functor<String>() {public String apply(String v) {return v.toUpperCase();}});
Not as concise, but not that horrible either. :)
I never quite liked operator overloading, because of infix notation all operators need to retain their precedence.
I never quite liked operator overloading, because of infix notation all operators need to retain their precedence.