When to use the equals sign in a Scala method declaration?

前端 未结 7 1303
春和景丽
春和景丽 2020-11-28 05:09

With equals sign:

object HelloWorld {
  def main(args: Array[String]) = {
    println(\"Hello!\")
  }
}

Without equals sign:



        
7条回答
  •  甜味超标
    2020-11-28 05:58

    For methods, Scala Style Guide recommends the equals syntax as opposed to procedure syntax

    Procedure Syntax

    Avoid the procedure syntax, as it tends to be confusing for very little gain in brevity.

    // don't do this
    def printBar(bar: Baz) {
      println(bar)
    }
    // write this instead
    def printBar(bar: Bar): Unit = {
      println(bar)
    }
    

提交回复
热议问题