The title asks the question. Basically I am using a java library that takes a String... as a parameter. How can I call that in my scala code?
I'll add a bit more:
from scala code
def myScalaFunc(params:String*) {
val myJavaClass = new JavaClass()
myJavaClass(params)
}
You have to expand the params
into a series of arguments, not just a single collection argument. The easiest way to do this is by saying params: _*
.
If the Java looks like:
public class VarargTest {
public void javaFunc(String... args) {
// something
}
}
Then the Scala caller looks like:
def scalaFunc(params: String*) =
(new VarargTest).javaFunc(params: _*)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With