如果我定义以下函数来返回一个函数:
def foo(): (Int*) => String = { is =>
is.map(_.toString).mkString(", ")
}
然后尝试进行引用:
val bar = foo()
bar(1, 2, 3)
我遇到了编译器错误
方法apply的参数过多(3个)...
但是当我明确定义引用类型时,它可以编译通过:
val bar2: (Int*) => String = foo()
bar2(4, 5, 6)
有没有办法可以定义我的函数foo()
而不需要这个显式的引用类型?
def foo(): (Int*) => String
does not seem to compile on my machine with Scala 2.13. I geterror: repeated parameters are only allowed in method signatures; use Seq instead
- Mario Galic