Is def x = 1 a function or a variable declaration? And, what is the difference between:
def x = 1 // REPL x: Int
def x() = 1 // REPL x: () Int
Looks like the first one is a variable definition. Please clarify.
Is def x = 1 a function or a variable declaration? And, what is the difference between:
def x = 1 // REPL x: Int
def x() = 1 // REPL x: () Int
Looks like the first one is a variable definition. Please clarify.
No difference at all. Braces are optional for methods with no arguments in Scala. It is a convention to use them, if the method modifies any kind of state, and to leave the away, if it does not (at the call site too).
Both are method definitions. var x = 1
or val x = 1
would be variable definitions.