Pass variable-length arguments to another function expecting the same?

送分小仙女□ 提交于 2019-12-12 10:56:35

问题


How to code this right in Scala?

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

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

I've tried putting an asterisk like

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

But this doesn't seem to work...


回答1:


Try this:

 myFun(strings: _*)

You need to tell it to split strings up across the varargs.



来源:https://stackoverflow.com/questions/10168101/pass-variable-length-arguments-to-another-function-expecting-the-same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!