我有一个字符串数组:
val str:Array[String] = Array("aa","bb")
scala> str.foreach(println) // works
aa
bb
scala> str.foreach(println()) // println() also returns a Unit, doesn't it?
^
error: type mismatch;
found : Unit
required: String => ?
为什么str.foreach(println)
工作没有问题,但str.foreach(println())
没有?
不println
等于println()
which 返回一个Unit
值吗?