Scala 在apply方法中,我应该在哪里定义隐式参数?
我想在apply方法中定义两个隐式参数Scala 在apply方法中,我应该在哪里定义隐式参数?,scala,Scala,我想在apply方法中定义两个隐式参数,如下所示: object WsGraph { def apply(logger: Logger, sink: Sink[Message, Future[Done]]) (implicit system: ActorSystem, implicit executor: ExecutionContextExecutor) { } } 但是编译器不允许这样做。如何正确操作?您只需在第二个参数列表的开头添加一个关键字implic
,如下所示:
object WsGraph {
def apply(logger: Logger, sink: Sink[Message, Future[Done]])
(implicit system: ActorSystem, implicit executor: ExecutionContextExecutor) {
}
}
但是编译器不允许这样做。如何正确操作?您只需在第二个参数列表的开头添加一个关键字implicit
,其中的所有参数都是隐式的:
object WsGraph {
def apply(logger: Logger, sink: Sink[Message, Future[Done]])
(implicit system: ActorSystem, executor: ExecutionContextExecutor) {
}
}
多个隐式参数不起作用。
应该是这样的:
object WsGraph {
def apply(logger: Logger, sink: Sink[Message, Future[Done]])
(implicit system: ActorSystem, executor: ExecutionContextExecutor) {
}
}
不理解您的问题,但请查看取出第二个隐式。如果“implicit”一词启动该组,则该参数组中的所有内容都是隐式的。在{
之前可能需要一个=
,否则不会返回任何内容。