val m = scala.collection.mutable.Map[String, Int]()
// this doesn t work
m += ("foo", 2)
// this does work
m += (("foo", 2))
// this works too
val barpair = ("bar", 3)
m += barpair
因此,如何处理<代码>m +=(“foo”),2)没有工作? 胎面错误:
error: type mismatch;
found : java.lang.String("foo")
required: (String, Int)
m += ("foo", 2)
^
Apparently Scala thinks that I am trying to call +=
with two arguments, instead of one tuple argument. Why? Isn t it unambiguous, since I am not using m.+=
?