将可变长度参数传递给另一个期望相同的函数? [英] Pass variable-length arguments to another function expecting the same?
本文介绍了将可变长度参数传递给另一个期望相同的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 Scala 中正确编码?
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)
}
我试过放一个星号
def myWraper(strings: String*) = {
// do something else and then call myFun with the dame input
myFun(strings*)
}
但这似乎不起作用...
But this doesn't seem to work...
推荐答案
试试这个:
myFun(strings: _*)
您需要告诉它在可变参数中拆分 strings
.
You need to tell it to split strings
up across the varargs.
这篇关于将可变长度参数传递给另一个期望相同的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文