|
|
|
|
|
by linuxhansl
5333 days ago
|
|
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. |
|