scala函数等号省略

例1:
此时没有写返回值,但是有等号,函数会自己推断返回值,此时的返回值是Int

def add(x:Int, y:Int) = {
x+y
}

例2:
此时没有写返回值,也没有等号,无论函数内部有没有返回值,返回值都是Unit

def add(x:Int, y:Int){
x+y
}

posted on 2018-11-02 09:29  cxhfuujust  阅读(322)  评论(0编辑  收藏  举报

导航