如何将 Java 双冒号运算符 (::) 翻译成 Scala?

How to translate the Java double colon operator (::) to Scala?

我想在我的 ScalaTests 中使用 camunda-bpm-assert-scenario

我有这个代码 receiveTask::receive:

when(documentRequest.waitsAtReceiveTask("ReceiveTaskWaitForDocuments")).thenReturn((receiveTask) -> {
  receiveTask.defer("P1DT1M", receiveTask::receive);
});

根据 中的回答,我可以很容易地将其翻译为:

receiveTask.defer("P1D", receiveTask.receive _)

但这给了我:

Error:(84, 45) type mismatch;
 found   : Unit
 required: org.camunda.bpm.scenario.defer.Deferred
       receiveTask.defer("P1D", receiveTask.receive _)

这是receive函数:

void receive();

这是预期的界面:

public interface Deferred {
  void execute() throws Exception;
}

我如何在 Scala 中实现这一点? 这不是 的重复,没有解决“错误:(84, 45) 类型不匹配; ..."

读完这个Whosebug answer,我可以解决它:

receiveTask.defer("P1D", new Deferred{
         def execute(): Unit = receiveTask.receive()
       })

Intellij 建议将其转换为 单一抽象方法:

receiveTask.defer("P1D", () => receiveTask.receive())

问题是 receive 还有一个带参数的重载函数。