演示了值函数,匿名函数,闭包。。。
其它具体的应用,还得在生产当中吧。。
这个告一段落。。其它SAM,CURRY,高阶函数,集合,泛型,隐式类。。这些,还是找专门的书去深入了解啦。。。
C:\Users\hengheng>scala Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_4 3). Type in expressions to have them evaluated. Type :help for more information. scala> def add(x : Int, y : Int) : Int = (x + y) add: (x: Int, y: Int)Int scala> var result = add _ result: (Int, Int) => Int = <function2> scala> result(1, 2) res0: Int = 3 scala> (x : Int) => x + 3 res1: Int => Int = <function1> scala> var fun = (x : Int) => x + 3 fun: Int => Int = <function1> scala> fun(7) res2: Int = 10 scala> var y = 1 y: Int = 1 scala> val sum = (x : Int) => x + y sum: Int => Int = <function1> scala> sum(5) res3: Int = 6 scala>
时间: 2024-10-23 15:59:36