将可变长度参数传递给期望相同的另一个函数?

时间:2012-04-16 02:34:26

标签: scala variadic-functions

如何在Scala中对此进行编码?

def myFun(strings: String*) = {
  // do something...
}

def myWraper(strings: String*) = {
  // do something else and then call myFun with the dame input
  myFun(strings)
}

我尝试过像

这样的星号
def myWraper(strings: String*) = {
  // do something else and then call myFun with the dame input
  myFun(strings*)
}

但这似乎不起作用......

1 个答案:

答案 0 :(得分:11)

试试这个:

 myFun(strings: _*)

你需要告诉它在varargs上分割strings

相关问题