1
访问值如何调用一个方法或访问一个参数通配符的价值?例如。在这个例子中,我想找到所有F对象的最大“rev”值。斯卡拉:调用方法/ on参数通配符
scala> case class F(rev:Long)
defined class F
scala> List(F(1),F(2),F(3))
res3: List[F] = List(F(1), F(2), F(3))
scala> res3.foldLeft(0L){math.max(_,_.rev)}
<console>:11: error: wrong number of parameters; expected = 2
res3.foldLeft(0L){math.max(_,_.rev)}
^
但这会不行吗?根据Scala规范,多个通配符被第一个参数,第二个参数,第三个参数等替代...上面的代码例如在'math.max(_,_)' –
@Sven查看更新。 –