It's a matter of style whether you choose to use parentheses to indicate a side-effecting method call.
By the way, if you declare a purely side-effecting method using =
, you should probably explicitly declare a Unit
return type, like this:
def a: Unit = println("hello")
Note that any type can be coerced to Unit
.
If you do not want to explicitly declare a return type, you should probably omit the =
. Then the compiler will infer a return type of Unit
, even if the last expression returns something different:
def a() { println("hello") }
Both of the above styles make refactoring safer, because modifying the method body will never cause the compiler to infer a different return type. IMO this explicitness of declaration is more important than call-site code style.
def a()()=println("hello")
....