0

java code

public void insertRow(Object... fieldList) {
  for(int i = 0; i < fieldList.length; i++) {
    System.out.println(fieldList[i]);
  }
 }

Scala code

 def main(args: Array[String]) {
    insertRow(args)
}

As show above, I want to call a method which write in java and has a non-fixed parameters. when I pass parameter in scala Array, it the fieldList.length is always 1 and just get the whole args not the element in scala array. so could someone tell me how to convert a scala array to java or how to pass a scala array to java ?

2

1 Answer 1

1

I think what you're looking for in this case is:

def main(args: Array[String]) {
  insertRow(args: _*)
}

Notice the _* syntax used to call the vararg method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.