我剛纔注意到,雖然我需要添加一對到地圖時澄清括號,我沒有做一個重新分配的時候需要他們:斯卡拉:奇怪添加到地圖
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) Server VM, Java 1.6.0_18).
Type in expressions to have them evaluated.
Type :help for more information.
給我一些值
scala> var n = Map.empty[Int, String]
n: scala.collection.immutable.Map[Int,String] = Map()
嘗試添加到地圖上沒有明確的括號:
scala> n + 1 -> ""
<console>:30: error: type mismatch;
found : Int(1)
required: (Int, ?)
n + 1 -> ""
^
未能按我預期。但通過重新分配做同樣的事情不會:
scala> n += 1 -> ""
scala> n
res12: scala.collection.immutable.Map[Int,String] = Map(1 -> "")
這是怎麼回事?爲什麼這不失敗?是scalac
添加parens本身?