Calling Scala constructor with multiple argument lists
In Scala, I can create a method that takes more than one argument list:
def myMethod(value: Int)(fn: (Int) => Unit) {
fn(value)
}
and call it like this:
myMethod(10) 开发者_如何学C{ value => println(value) }
How can I do the same thing with a class constructor? How do I call it?
This works.
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) Client VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class MyClass(val value: Int)(val fn: Int => Unit)
defined class MyClass
scala> new MyClass(10)({value => println(value)})
res0: MyClass = MyClass@17577f9
精彩评论