6

I have a method in Java with this signature void setActiveProfiles(String... profiles), and in Java I can pass an array of string to this method. I want to call the method and pass it an Array[String], but I got Type mismatch error. And my question is what is the best and optimal way to convert Scala array to Java array?

This is the body of compilation error:

type mismatch;
 found   : Array[String]
 required: String
6
  • 1
    Can you display the error. Are you trying to send Java array to scala function? Commented Jul 31, 2013 at 7:24
  • No, I want to call the Java method with vararg parameter in Scala Commented Jul 31, 2013 at 7:27
  • 6
    I think my answer is setActiveProfiles(array:_*) Commented Jul 31, 2013 at 7:32
  • 1
    You dont have to do anything. If you have a java function and it expects a String[] then scala compiler will itself convert Array[String] to String[]. Please show the error Commented Jul 31, 2013 at 7:35
  • @Jatin No, because parameter type is Vararg Commented Jul 31, 2013 at 7:47

1 Answer 1

4

I've found the answer and I've tested it, call method as setActiveProfiles(array:_*)

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

1 Comment

Perhaps you could change your question to match your answer?

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.