做了如下实验,但理解不了:
scala> var f1= ()=>{println("anoum")}f1: () => Unit = $$Lambda$1182/522007047@ 4dd94931scala> f1res10: () => Unit = $$Lambda$1182/522007047@ 4dd94931scala> f1()anoumscala> println(f1())anoum()
另外,还做如下实验:
scala> Array(3.14,1.42,2.0).map((x:Double) => 3*x)res13: Array[Double] = Array(9.42, 4.26, 6.0)scala> Array(3.14,1.42,2.0).map{(x:Double) => 3*x}res14: Array[Double] = Array(9.42, 4.26, 6.0)scala> Array(3.14,1.42,2.0) map((x:Double) => 3*x) //中置法不需要“."res15: Array[Double] = Array(9.42, 4.26, 6.0)scala> Array(3.14,1.42,2.0) map{(x:Double) => 3*x} //中置法不需要“.",匿名函数作为参数,如果你愿意,可以将小括号换成大括号,正常函数参数时则不能将小括号换成res16: Array[Double] = Array(9.42, 4.26, 6.0)