让我们想象一下范围内的以下项目:
object Thing {
var data: Box[String] = Empty
}
def perform[T](setter: Box[T] => Unit) {
// doesn't matter
}
以下无法编译:
perform(Thing.data = _)
错误信息是:
<console>:12: error: missing parameter type for expanded function ((x$1) => Thing.data = x$1)
perform(Thing.data = _)
^
<console>:12: warning: a type was inferred to be `Any`; this may indicate a programming error.
perform(Thing.data = _)
^
虽然以下编译:
perform(Thing.data_=)
从那以后,我通过创建一个更好的抽象来超越这个问题,但我的好奇心仍然存在。
谁能解释这是为什么?