In any method invocation in Scala in which you're passing in exactly one argument, you can opt to use curly braces to surround the argument instead of parentheses.
For example, instead of:
scala> println("Hello, world!")
Hello, world!
You could write:
scala> println { "Hello, world!" }
Hello, world!
This curly braces technique will work, however, only if you're passing in one argument. Here's an attempt at violating that rule:
scala> val g = "Hello, world!"
g: java.lang.String = Hello, world!
scala> g.substring { 7, 9 }
<console>:1: error: ';' expected but ',' found.
g.substring { 7, 9 }
^
Login in to like
Login in to comment