What does a method turn into with the equal sign left out in Scala?

后端 未结 1 568
灰色年华
灰色年华 2021-01-26 00:05

I\'ve just found out that it\'s possible not to use the sign of = when defining a method in Scala.

def someMethod(a: Int) {
  println(a)
  println(\         


        
相关标签:
1条回答
  • 2021-01-26 00:29

    Such method definition is called procedure. It's a special syntax for Unit-returning methods:

    def someMethod(a: Int): Unit = {
      println(a)
      println("---------")
    }
    

    It's not a recommended syntax. Martin Odersky believes it was a bad decision to include this syntax. See Keynote - Scala with Style chapter 45.

    0 讨论(0)
提交回复
热议问题