我一直在用:_*
转换 Seq[String]
至 String*
我意识到我不明白这是如何运作的。
有没有一种简单的方法来考虑这个问题?
最佳答案
在引擎盖下,String*
作为 Seq[String]
传递.这只是语法糖:
def blah(ss: String*) = {...}
blah("Hi","there")
变成了
def blah(ss: Seq[String]) = {...}
blah(Seq("Hi", "there"))
和
:_*
只是意味着“拿着糖,我已经得到了你需要的东西——一个序列!”
关于scala - :_* convert ordered collections into variable arg lists? 怎么样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9488413/