在 Scala Play 2.2.x 测试的背景下,我有一个Map[String, String]
我需要将其传递给接受的函数(String, String)*
即一个可变参数(String, String)
tuple.
e.g.
val data : Map[String, String] = Map("value" -> "25", "id" -> "", "columnName" -> "trades")
route(FakeRequest(POST, "/whatever/do").withFormUrlEncodedBody(data))
但这会导致类型不匹配,因为withFormUrlEncodedBody
只接受一个(String, String)*
type.
Simply:
def foo(names: (String, String)*) = names.foreach(println)
val folks = Map("john" -> "smith", "queen" -> "mary")
foo(folks.toSeq:_*)
// (john,smith)
// (queen,mary)
Where _*
是对编译器的提示 https://stackoverflow.com/questions/6051302/what-does-colon-underscore-star-do-in-scala.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)