Converting Map[String, Double] to java.util.Map[String, java.lang.Double]

前端 未结 3 1889
野趣味
野趣味 2021-01-14 15:15

I thought we can rely on implicit conversion which converts scala.Double to java.lang.Double. So I tried the following:

import scal         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-14 15:41

    It seems that for String, you don't need to do any conversion, but is not the case for Double. You can use the method double2Double which is defined in Predef to convert to java.double.

    import scala.collection.JavaConverters._
    
    m.map { case (k, v) => k -> double2Double(v) }.asJava
    

    or another way is to do asInstanceOf to convert it to Java map directly.

提交回复
热议问题