Scala: pass Seq to var-args functions

后端 未结 1 2055
既然无缘
既然无缘 2020-12-01 02:49

Given a function that takes a variable number of arguments, e.g.

def foo(os: String*) =
  println(os.toList)

How can I pass a sequence of a

相关标签:
1条回答
  • 2020-12-01 02:59

    foo(args:_*) does the trick. Instead of applying the sequence as one single argument, each element in the sequence will be used as an argument.

    0 讨论(0)
提交回复
热议问题