【发布时间】:2015-03-12 11:43:29
【问题描述】:
我想将类实例的成员函数作为第一类函数分配给变量:
class A(val id:Int){ def f(u:Int)=id+u }
val a= new A(0)
val h=a.f // fails: interpreted as a.f(with missing parameter u)
val h1 = (u:Int)=>a.f(u) // OK and does what we want
我们可以通过分配一个合适的匿名函数来获得想要的效果。 这是唯一的方法吗? 我搜索了但根本找不到参考。
【问题讨论】:
标签: function scala class member