Hi I have following code
CookieMock(response, email).cookies: _*
.cookies is type def cookies: scala.Seq[Cookie].
What does :_* mean in Scala?
Thanks
If you are familiar with Java
here is the same explanation in Java:
Because * is not a type, you add the underscore.
def printInts(ints: Int*) = ints.mkString(",")
printInts(1,2,3)
//printInts(List(1,2,3)) //type mismatch; found : List[Int] required: Int
printInts(List(1,2,3): _*)
paste this to codebrew.io this will clarify.
The : is type ascription. _* is the type you ascribe when you need a Seq[A] to be treated as A*.
http://docs.scala-lang.org/style/types.html
The following are examples of ascription:
Nil: List[String] Set(values: _*) "Daniel": AnyRefAscription is basically just an up-cast performed at compile-time for the sake of the type checker. Its use is not common, but it does happen on occasion. The most often seen case of ascription is invoking a varargs method with a single Seq parameter. This is done by ascribing the _* type (as in the second example above).