Sometimes it is usefull to name lambdas. Especially when you pass them around as parameter.
A realy simple example is
public class Main {
publi
Here's an alternative that comes to mind:
static Predicate nameIt(String name, Predicate super T> pred) {
return new Predicate() {
public String toString() { return name; }
public boolean test(T t) { return pred.test(t); }
};
}
This seems pretty simple. Although I haven't benchmarked it, it seems like it ought to be pretty fast. It adds a single object and one method call, and it avoids boxing/unboxing overhead.
The drawback is that you have to write a little function like this for every functional interface for which you want to provide named instances.