File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -28,19 +28,19 @@ x match {
28
28
case 0 => "zero"
29
29
case 1 => "one"
30
30
case 2 => "two"
31
- case _ => "many "
31
+ case _ => "other "
32
32
}
33
33
```
34
- 上述代码中的` val x ` 是一个0到10之间的随机整数,将它放在` match ` 运算符的左侧对其进行模式匹配,` match ` 的右侧是包含4条` case ` 的表达式,其中最后一个` case _ ` 表示匹配其余所有情况,在这里即是 ` x ` 大于2的情况 。
34
+ 上述代码中的` val x ` 是一个0到10之间的随机整数,将它放在` match ` 运算符的左侧对其进行模式匹配,` match ` 的右侧是包含4条` case ` 的表达式,其中最后一个` case _ ` 表示匹配其余所有情况,在这里就是其他可能的整型值 。
35
35
36
36
` match ` 表达式具有一个结果值
37
37
``` tut
38
38
def matchTest(x: Int): String = x match {
39
39
case 1 => "one"
40
40
case 2 => "two"
41
- case _ => "many "
41
+ case _ => "other "
42
42
}
43
- matchTest(3) // many
43
+ matchTest(3) // other
44
44
matchTest(1) // one
45
45
```
46
46
这个` match ` 表达式是String类型的,因为所有的情况(case)均返回String,所以` matchTest ` 函数的返回值是String类型。
You can’t perform that action at this time.
0 commit comments