我正在使用第三方库,正在尝试做一些抽象操作,并且遇到了一个接受varargs但未使用类型描述的方法的问题。就像是:
def outer(otherStuff:String*): Unit ={
if(someCondition)
methodInThirdPartyLibrary(otherStuff)
// other code....
}
def methodInThirdPartyLibrary(stuff:String*): Unit ={
println(stuff.mkString(","))
}
Run Code Online (Sandbox Code Playgroud)
给定库如何设置方法,是否有任何方法可以传递参数?
您只需要使用特殊的:_*传播名称:
def outer(otherStuff:String*): Unit ={
if(someCondition)
methodInThirdPartyLibrary(otherStuff: _*)
// other code....
}
Run Code Online (Sandbox Code Playgroud)
还要检查这个答案。
| 归档时间: |
|
| 查看次数: |
37 次 |
| 最近记录: |