Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass variadic arguments while adding another one in Scala?

Consider these methods:

def clearlnOut(coll : Any*)
{
  clearOut(coll:_*,"\n") // error
}
def clearOut(coll : Any*)
{
  ...

The compiler says:

error: no `: _*' annotation allowed here (such annotations are only allowed in arguments to *-parameters)

Now I am puzzled. It is clear case of using variadic arguments, so how to pass such augmented "collection" properly?

like image 963
greenoldman Avatar asked Dec 01 '11 21:12

greenoldman


1 Answers

Try this:

def clearlnOut(coll : Any*) {
  clearOut(coll ++ "\n")
}

UPDATE: much better version suggested by @Rex Kerr (see comment below):

def clearlnOut(coll : Any*) {
  clearOut((coll :+ "\n"): _*)
}
like image 179
Tomasz Nurkiewicz Avatar answered Oct 15 '22 06:10

Tomasz Nurkiewicz