演示了值函数,匿名函数,闭包。。。
其它具体的应用,还得在生产当中吧。。
这个告一段落。。其它SAM,CURRY,高阶函数,集合,泛型,隐式类。。这些,还是找专门的书去深入了解啦。。。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
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
=
<function
2
>
scala> result(
1
,
2
)
res
0
:
Int
=
3
scala> (x
:
Int)
=
> x +
3
res
1
:
Int
=
> Int
=
<function
1
>
scala>
var
fun
=
(x
:
Int)
=
> x +
3
fun
:
Int
=
> Int
=
<function
1
>
scala> fun(
7
)
res
2
:
Int
=
10
scala>
var
y
=
1
y
:
Int
=
1
scala>
val
sum
=
(x
:
Int)
=
> x + y
sum
:
Int
=
> Int
=
<function
1
>
scala> sum(
5
)
res
3
:
Int
=
6
scala>
|