0

I am Scala newbie

I have a java method like this below

public void myMethod (Collection<String> param) throws MyException {
    // process param
}

I want to test this method using a Scala Junit test

@Test
def myMethodTest() {
    try {
        ....myMethod(Seq("myString"))
    } catch {
        case e : MyException => throw new AssertionError ("Failed myMethod : " + e.getMessage)
    }
}

But it is giving me a Type mismatch error. How can I fix this?

yalkris
  • 2,596
  • 5
  • 31
  • 51
  • http://stackoverflow.com/questions/17737631/convert-from-scala-collection-seqstring-to-java-util-liststring-in-java-code – kdabir Apr 10 '14 at 18:49

1 Answers1

3

Seq is not a Java Collection. You should use JavaConverters implicits to convert them:

import scala.collection.JavaConverters._

myMethod(Seq("myString").asJava)

Or you can use Java collections directly, for example, via Arrays.asList():

import java.util.Arrays

myMethod(Arrays.asList("myString"))
Vladimir Matveev
  • 120,085
  • 34
  • 287
  • 296