block of code as a param
— ex:
if we have a function likedef example(name:string){
var char = name[0]
char+'good'
}={
}
the function example want to receive two params
- name
- the result of certain block of code (we need use {} for the code block)
if - else
var x = 30; |
这个语法很普通 js一样一样的
Pattern matching
def matchTest(x: Any): Any = x match { |
模式匹配首先很想switch.
逐个匹配然后返回值.
匹配比switch 更灵活
y:Int
可以加类型y
算是把匹配项付给临时的变量- 可以给匹配项再加条件筛选
y:Int if y >4
_
相当于匹配任何值,类似switch 的default