2

I am working with a third party library and am trying to do some abstractions and am running into an issue with a method that accepts varargs but is not using type ascription. Something like:

  def outer(otherStuff:String*): Unit ={
    if(someCondition)
      methodInThirdPartyLibrary(otherStuff)
    // other code....
  }

  def methodInThirdPartyLibrary(stuff:String*): Unit ={
    println(stuff.mkString(","))
  }

Given how the library has the method setup is there any way for me to pass in the arguments?

adambsg
  • 131
  • 2
  • 9
  • Your question is unclear to me. Can you explain what it means that the method "accepts varargs but is not using type ascription"? Why would it matter whether the method uses type ascription or not? – Jörg W Mittag May 11 '19 at 03:45

1 Answers1

6

You just need to use special :_* spread ascription:

def outer(otherStuff:String*): Unit ={
   if(someCondition)
     methodInThirdPartyLibrary(otherStuff: _*)
   // other code....
}

Also check out this anwser.

Krzysztof Atłasik
  • 21,985
  • 6
  • 54
  • 76