【发布时间】:2020-07-04 12:12:27
【问题描述】:
我正在使用 io.vavr.control.Try 并尝试执行 Try.run 但我不能使用带参数的方法引用。我该如何解决这个问题?
PingRequest pingRequest = new PingRequest();
PingCall pingCall = this.client.newPingCall();
//Try<Void> attempt = Try.run(pinCall::call); //A: this will work if call is a no parameter method
//Try<Void> attempt = Try.run(pinCall.call(pingRequest)); //B: I want to call it with parameter but obvious it can't: Required type: CheckedRunnable
Try<Void> attempt = Try.run(() -> pingCall.call(pingRequest)); //C: Idea pass this way, but I don't know if it's correct
attempt.onSuccess...
public PingResponse call(PingRequest input) throws InternalError {...}
【问题讨论】:
标签: java java-8 method-reference vavr