1

What is the difference between using parantheses and curly braces in function and method declaration?

def test() = (
  expression
  expression
)

and

def test() = {
  expression
  expression
}
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
  • 1
    maybe you will get help from here [http://stackoverflow.com/questions/4386127/what-is-the-formal-difference-in-scala-between-braces-and-parentheses-and-when] – Java Feb 27 '12 at 13:03

2 Answers2

5

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.

Daniel C. Sobral
  • 295,120
  • 86
  • 501
  • 681
4

The difference is that the first one doesn't compile ;)

agilesteel
  • 16,775
  • 6
  • 44
  • 55