将可变长度参数传递给期望相同的另一个函数?
问题描述:
如何在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*)
}
但是这似乎并没有工作...
答
试试这个:
myFun(strings: _*)
您需要告诉它分开strings
跨越可变参数。
谢谢。那正是我正在寻找的。我不记得它是如何写的。我也尝试了下划线,但它是所有这3个符号:-) – Ivan 2012-04-16 03:31:59