可以使用或不使用括号()来定义0-arity的Scala方法。这用于向用户发出该方法具有某种副作用(如打印输出或破坏数据),而不是以后可以实现为val。
Such parameterless methods are quite common in Scala. By contrast,methods defined with empty parentheses,such as def height(): Int,are called empty-paren methods. The recommended convention is to use a parameterless method whenever there are no parameters and the method accesses mutable state only by reading fields of the containing object (in particular,it does not change mutable state).
This convention supports the uniform access principle […]
To summarize,it is encouraged style in Scala to define methods that take no parameters and have no side effects as parameterless methods,i.e.,leaving off the empty parentheses. On the other hand,you should never define a method that has side-effects without parentheses,because then invocations of that method would look like a field selection.