You can’t use method references for this purpose. You have to resort to lambda expressions. The reason why the bind2
method of the linked question doesn’t work is that you are actually trying to bind two parameters to convert a three-arg function into a one-arg function. There is no similarly simple solution as there is no standard functional interface
for three-arg consumers.
It would have to look like
interface ThreeConsumer<T, U, V> {
void accept(T t, U u, V v);
}
public static <T, U, V> Consumer<T> bind2and3(
ThreeConsumer<? super T, U, V> c, U arg2, V arg3) {
return (arg1) -> c.accept(arg1, arg2, arg3);
}
Then .forEach(bind2and3(Node::findChildren, name, result));
could work. But is this really simpler than .forEach(node -> node.findChildren(name, result));
?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…