按名称调用列表元素?

时间:2016-10-11 13:26:59

标签: scala

以下函数f以名字方式调用参数:

scala> def f(xs: => List[Int]) = xs
f: (xs: => List[Int])List[Int]

然后,我尝试使用List of call by-name参数定义一个函数:

scala> def f(xs: List[=> Int]) = xs
<console>:1: error: identifier expected but '=>' found.
def f(xs: List[=> Int]) = xs
               ^

但那失败了。

我能做到:

scala> def f(xs: List[Function0[Int]]) = xs
f: (xs: List[() => Int])List[() => Int]

但是,是否可以使用List语法在=>的参数上使用call-by?

0 个答案:

没有答案