아래 예제 코드에서 chainWanted
메서드와 같이 BiFunctions를 연결하고 싶습니다.BiFunctions를 체인화하는 방법은 무엇입니까?
BiFunction은 AndThen의 매개 변수로 Function을 사용합니다. 어떻게 든 BiFunctions를 연결할 수 있습니까?
여기의 코드는 컴파일되지 않아 BiFunction을 함수로 캐스팅 할 수 없습니다.
import java.util.function.BiFunction;
import java.util.function.Function;
import org.openqa.selenium.remote.RemoteWebDriver;
public class Wf {
BiFunction<RemoteWebDriver, WfParams, RemoteWebDriver> init = this::init;
BiFunction<RemoteWebDriver, WfParams, RemoteWebDriver> wait = this::wait;
BiFunction<RemoteWebDriver, WfParams, RemoteWebDriver> chainNow = init
.andThen(d -> {
System.out.println("--------------");
return null;
});
BiFunction<RemoteWebDriver, WfParams, RemoteWebDriver> chainWanted = init
.andThen((BiFunction) wait);
public RemoteWebDriver init(RemoteWebDriver d, WfParams params) {
System.out.println("init(d, params)");
return d;
}
public RemoteWebDriver wait(RemoteWebDriver d, WfParams params) {
System.out.println("Wf.wait(d, params)");
return d;
}
public static void main(String[] args) throws Exception {
new Wf().start();
}
private void start() {
chainNow.apply(null, null);
}
}
두 가지 기능을 시작할 수있는 체인을 연결하는 방법을 알지 못합니다. bifunction의 결과는 하나의 인수입니다. 어떻게 다른 인수로 연결하려고합니까? – fge