我希望能夠執行以下操作,但在調用useMap時失敗。我如何執行此轉換?我怎樣才能將Scala地圖轉換成Java Map使用scala.Float轉換成java.Float k/v轉換
scala> import scala.collection.JavaConversions._
import scala.collection.JavaConversions._
scala> import scala.collection.JavaConverters._
import scala.collection.JavaConverters._
scala> def useMap(m: java.util.Map[java.lang.Integer, java.lang.Float]) = m
useMap: (m: java.util.Map[Integer,Float])java.util.Map[Integer,Float]
scala> val v: Map[Int, Float] = Map()
v: Map[Int,Float] = Map()
scala> useMap(v)
<console>:10: error: type mismatch;
found : scala.collection.immutable.Map[Int,scala.Float]
required: java.util.Map[Integer,java.lang.Float]
useMap(v)
^
它似乎與Map [String,String]一起使用,但不是Map [Int,Float]。
看看[http://stackoverflow.com/questions/6991340/scala-convert-listint-to-a-java-util-listjava-lang-integer](http://stackoverflow.com/問題/ 6991340/scala-convert-listint -a-java-util-listjava-lang-integer) –