给定一个带有可变数量参数的函数,例如
def foo(os: String*) =
println(os.toList)
Run Code Online (Sandbox Code Playgroud)
如何将一系列参数传递给函数?我想写:
val args = Seq("hi", "there")
foo(args)
Run Code Online (Sandbox Code Playgroud)
显然,这不起作用.
Joa*_*ert 116
foo(args:_*)诀窍.不是将序列应用为单个参数,而是将序列中的每个元素用作参数.