0

I have a function like below which is auto generated by a script.

def printFunc(args : Any*) : Unit = {
     funcCallHandler.call(args)
}

The call function in the funcCallHandler looks like this. This function takes variable arguments from other generated functions too.

def call(args : Any*) : Unit = {

   for (arg <- args) {
       /*Check type using a match function
        and add do the rest of the code*/
   }

}

When I am passing the variable arguments I got from the first function to the second mentioned one I get it as a WrappedArray. Is there a way to type match this WrappedArray or is there a better approach at doing this?

The type is not specified in the case of first function.

Will_Panda
  • 534
  • 10
  • 26
  • 3
    Possible duplicate of [How to pass scala Array into scala vararg method?](https://stackoverflow.com/questions/31064753/how-to-pass-scala-array-into-scala-vararg-method) – Davis Broda May 31 '17 at 14:04
  • 1
    @DavisBroda The fact that `args` is itself a varargs is a different information and might be confusing (although the solution is the same indeed). – Cyrille Corpet May 31 '17 at 14:06
  • `funcCallHandler.call(args:_*)` – Dima May 31 '17 at 14:55

1 Answers1

4

To pass the arguments as varargs, you need to do

 def printFunc(args : Any*) : Unit = {
   funcCallHandler.call(args: _*)
}

Otherwise, args will be understood as a single argument of type Seq[Any].

Cyrille Corpet
  • 5,265
  • 1
  • 14
  • 31