What is the difference between using parantheses and curly braces in function and method declaration?
def test() = (
expression
expression
)
and
def test() = {
expression
expression
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.