Primitive and reference types are much less different in scala than in java, and so the convention is that the name starts with a capital letter for all of them. Double scala.Double , which is a primitive java Double , and not a java.lang.Double reference.
If you need a “double or no value” in scala, you would most often use Option[Double] . The variant has strong library support, and the type system will not let you ignore that there can be no value. However, when you need to work closely with java, as in your example, your table contains java.lang.Double, and you have to say that.
val a = new java.util.HashMap[String, java.lang.Double]
If java.lang.Double starts to appear everywhere in your code, you can use the JDouble alias, either by importing
import java.lang.{Double => JDouble}
or defining
type JDouble = java.lang.Double
There are implicit conversions between scala.Double and java.lang.Double , so the interaction should be smooth enough. However, java.lang.Double should probably be limited to the scala / java interaction layer, it would be difficult to inject it into scala code.
source share