What is the difference between using parantheses and curly braces in function and method declaration?
def test() = (
expression
expression
)
and
def test() = {
expression
expression
}
What is the difference between using parantheses and curly braces in function and method declaration?
def test() = (
expression
expression
)
and
def test() = {
expression
expression
}
Parenthesis delimit one expression, while curly braces delimit a series of statements and declarations, whose value is equal to the last statement.
So, parenthesis won't have semi-colon inference, which makes it well suited to breaking up a big line (a long chain of method calls) into multiple lines.
On the other hand, you can't declare anything in it, and, naturally, you can't have multiple statements.