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

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

With equals sign:

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

Without equals sign:



        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 05:48

    for method that dont have a return value, a way to express such methods is leaving out the result type and the equals sign, following the method with a block enclosed in curly braces. In this form, the method looks like a procedure, a method that is executed only for its side effects.

提交回复
热议问题