I have a Java method takes an argument of type Map<Long, Foo>
. I am trying to write a unit test for that method in Scala 2.8.1 and pass in a literal Map[Long, Foo]
.
My code looks like this:
import collection.JavaConversions._
x.javaMethod(asJavaMap(Map(1L -> new Foo, 2L -> new Foo)))
The compiler is giving me the following error:
error: type mismatch;
found : scala.collection.immutable.Map[scala.Long,Foo]
required: scala.collection.Map[java.lang.Long,Foo]
I also tried it with
import collection.JavaConverters._
x.javaMethod(Map(1L -> new Foo, 2L -> new Foo))
and
import collection.JavaConversions._
x.javaMethod(Map(1L -> new Foo, 2L -> new Foo))
and got the error:
error: type mismatch;
found : scala.collection.immutable.Map[scala.Long,Foo]
required: java.util.Map[java.lang.Long,Foo]
How do I do this?