I have a code
object App {
def main(args: Array[String]) = print {CL().f()()()}
}
case class CL() {
def f()()() = 1
}
You can see there a method call f()()()
. But if I execute f()
it returns the same result.
So what is the difference betweenn f()()()
and f()
in Scala?
In Scala, methods can have multiple parameter lists:
def f(x: Int)(y: Int, z: String)(w: Boolean) = "foo"
f(1)(2, "bar")(true) //returns "foo"
Multiple parameter lists are useful for several reasons. You can read more about them on this question.
Also in Scala, an empty argument list can be optionally omitted:
def f() = "foo"
f //returns "foo"
The choice of using an empty parameter list is generally governed by convention, as explained in this question.
So, if you have multiple empty argument lists, you can omit any of them:
def f()()() = "foo"
f()()() //returns "foo"
f()() //returns "foo"
f() //returns "foo"
f //returns "foo"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With