oll*_*erg 12
你应该使用apply方法:
class Foo (y: Int) {
def apply(x: Int) : Int = x + y
}
val foo : Foo = new Foo (7)
val fooBar = foo (5)
println(fooBar)
Run Code Online (Sandbox Code Playgroud)
然后运行代码:
bash$ scala foo.scala
12
Run Code Online (Sandbox Code Playgroud)