我确定答案很简单,但我陷入了困境:
Welcome to Scala version 2.7.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_14). Type in expressions to have them evaluated. Type :help for more information. scala> def f(x:Int*)=0 f: (Int*)Int scala> val xs:Seq[Int]=1::2::3::4::Nil xs: Seq[Int] = List(1, 2, 3, 4) scala> f (xs):7: error: type mismatch; found : Seq[Int] required: Int f (xs) ^
我如何构建'Int*'?
要将序列解压缩到参数列表中,请使用 _*
scala> f(xs: _*) res1: Int = 0