【发布时间】:2022-09-28 10:32:36
【问题描述】:
在 Scala 2 中,我可以这样写:
// a function that needs an implicit context
def funcWithCtx(arg1: String)(implicit ctx: Context) = ???
myObj.doSomething { implicit ctx => // mark argument as the implicit context
funcWithCtx(\"arg1\")
}
这种语法在 Scala 3 中有效,但我认为 implicit 已被弃用,而 given \\ using 正在被使用?我尝试用given 替换implicit,但编译器不喜欢这样。
myObj.doSomething { given x => // this fails!
...
}
这是仍然需要implicit 关键字的地方吗?
-
耸耸肩新语法更加混乱和混乱。
-
我又增加了一个选项。