To understand it, lets take an example
scala> def echo(args: String*) =
for (arg <- args) println(arg)
echo: (args: String*)Unit
scala> val arr = Array("What's", "up", "doc?")
arr: Array[String] = Array(What's, up, doc?)
scala> echo(arr)
<console>:14: error: type mismatch;
found : Array[String]
required: String
echo(arr)
scala> echo(arr: _ *)
What's
up
doc?
This notation,arr:_*
tells the compiler to pass each element of arr as its own argument to echo
, rather than all of it as a single argument.