I am trying to use the foreach
method on scala.collection.immutable.Map
. But no matter how I change my format, I receive a compilation error. I have referenced the question: Scala Map foreach, but it still doesn't work:
val m = Map[String, Int]("a" -> 1, "b" -> 2, "c" -> 3)
m.foreach(p => println(">>> key=" + p._1 + ", value=" + p._2))
or:
val m = Map[String, Int]("a" -> 1, "b" -> 2, "c" -> 3)
m.foreach((e: (String, Int)) => println(e._1 + "=" + e._2))
both report:
type mismatch; found : Unit required: String
My Scala library version is 2.10.4 and my eclipse version is Release 4.3.2.