我有一个 Java 方法需要一个类型的参数Map<Long, Foo>
。我正在尝试在 Scala 2.8.1 中为该方法编写一个单元测试并传入一个文字Map[Long, Foo]
.
我的代码如下所示:
import collection.JavaConversions._
x.javaMethod(asJavaMap(Map(1L -> new Foo, 2L -> new Foo)))
编译器给我以下错误:
error: type mismatch;
found : scala.collection.immutable.Map[scala.Long,Foo]
required: scala.collection.Map[java.lang.Long,Foo]
我也试过了
import collection.JavaConverters._
x.javaMethod(Map(1L -> new Foo, 2L -> new Foo))
和
import collection.JavaConversions._
x.javaMethod(Map(1L -> new Foo, 2L -> new Foo))
并得到错误:
error: type mismatch;
found : scala.collection.immutable.Map[scala.Long,Foo]
required: java.util.Map[java.lang.Long,Foo]
我该怎么做呢?