我有一个带有默认参数的无副作用的方法,我想在没有括号的情况下调用它,例如:
scala> def foo(x: Int = 1) = 42
foo: (x: Int)Int
scala> foo
<console>:9: error: missing arguments for method foo in object $iw;
follow this method with `_' if you want to treat it as a partially applied function
foo
^
scala> foo()
res3: Int = 42
这是故意的还是暂时的限制?
答案 0 :(得分:9)
这可能是故意的,所以你不会让参数块消失在你身上:
def foo(x: Int = 2)(y: Int = 4) = x*y
foo(3) // What does this mean???