What's the difference between using and no using a “=” in Scala defs ?

后端 未结 5 687
情歌与酒
情歌与酒 2021-01-21 11:06

What the difference between the two defs below

def someFun(x:String) { x.length } 

AND

def someFun(x:String) = {          


        
5条回答
  •  一生所求
    2021-01-21 11:36

    The former is

    def someFun(x: String): Unit = {
      x.length
      ()  // return unit
    }
    

    And the latter is

    def someFun(x: String): Int = {
      x.length  // returned
    }
    

提交回复
热议问题