java 可变长度参数列表,Scala:将元组列表展开为元组的可变长度参数列表

我很困惑如何将List / Seq / Array扩展为可变长度参数列表 .

鉴于我有test_func函数接受元组:

scala> def test_func(t:Tuple2[String,String]*) = println("works!")

test_func: (t: (String, String)*)Unit

当我传递元组时,哪个有效:

scala> test_func(("1","2"),("3","4"))

works!

从阅读Scala参考资料中我得到了强烈的印象,即以下内容也可以起作用:

scala> test_func(List(("1","2"),("3","4")))

:9: error: type mismatch;

found : List[(java.lang.String, java.lang.String)]

required: (String, String)

test_func(List(("1","2"),("3","4")))

^

还有一次绝望的尝试:

scala> test_func(List(("1","2"),("3","4")).toSeq)

:9: error: type mismatch;

found : scala.collection.immutable.Seq[(java.lang.String, java.lang.String)]

required: (String, String)

test_func(List(("1","2"),("3","4")).toSeq)

如何将List / Seq / Array扩展为参数列表?

先感谢您!

你可能感兴趣的:(java,可变长度参数列表)