apply()
有人可以解释为什么之后需要明确调用map()
scala> val l = List(1, 2, 3)
l: List[Int] = List(1, 2, 3)
scala> l(2)
res56: Int = 3
scala> l.map(x => x*2)
res57: List[Int] = List(2, 4, 6)
scala> l.map(x => x*2)(2)
<console>:9: error: type mismatch;
found : Int(2)
required: scala.collection.generic.CanBuildFrom[List[Int],Int,?]
l.map(x => x*2)(2)
^
scala> l.map(x => x*2).apply(2)
res59: Int = 6
谢谢。