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

后端 未结 5 688
情歌与酒
情歌与酒 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:44

    Note that the Scala Style guide always recommend using '=', both in

    • method declaration

    Methods should be declared according to the following pattern:

    def foo(bar: Baz): Bin = expr
    
    • function declaration

    Function types should be declared with a space between the parameter type, the arrow and the return type:

    def foo(f: Int => String) = ...
    def bar(f: (Boolean, Double) => List[String]) = ...
    

提交回复
热议问题