scala map("key") = "value" 如何转换为 map.update("key", "value")?
How does scala map("key") = "value" translate to map.update("key", "value")?
我知道 map("key")
是可能的,因为 Map
实现了 Function1
。但是 map("key") = "value"
是如何转化为 map.update("key", "value")
的呢?我没有在 Map
或其父接口
中的任何地方看到定义的 =
函数
这种翻译只是在 Scala 编译器中作为规则实现的。见 Scala Language Specification:
An assignment f(args) = e with a function application to the left of
the ‘=’ operator is interpreted as f.update(args, e), i.e. the
invocation of an update function defined by f.
我知道 map("key")
是可能的,因为 Map
实现了 Function1
。但是 map("key") = "value"
是如何转化为 map.update("key", "value")
的呢?我没有在 Map
或其父接口
=
函数
这种翻译只是在 Scala 编译器中作为规则实现的。见 Scala Language Specification:
An assignment f(args) = e with a function application to the left of the ‘=’ operator is interpreted as f.update(args, e), i.e. the invocation of an update function defined by f.