scala: 'def foo = {1}' vs 'def foo {1}'

后端 未结 2 1742

what is going on in each of these forms of defining foo?:

scala> def foo = {1}
foo: Int

scala> foo
res2: Int = 1

But:



        
2条回答
  •  [愿得一人]
    2020-12-06 17:44

    found this in http://anyall.org/scalacheat/:

    //[bad!] 
    def f(x: Int) { x*x } //hidden error: without = it's a Unit-returning proc; causes havoc 
    

提交回复
热议问题