2

Both of these below appear to be declarations of parameterless methods named x that return an Int of 5. Why can the first not be invoked with empty parens, while the other can?

scala> def x = 5
x: Int

scala> x
res1: Int = 5

scala> x()
<console>:9: error: Int does not take parameters
              x()
               ^

scala> def x() = 5
x: ()Int

scala> x()
res3: Int = 5

scala> x
res4: Int = 5
stantonk
  • 1,922
  • 1
  • 18
  • 24

0 Answers0