class Double 是抽象的;不能在scala中实例化

class Double is abstract; cannot be instantiated in scala

object demo 
{
  def main(args:Array[String]):Unit=
  {
      val temp: LinkedHashMap[String,Object]=new 
      LinkedHashMap[String,Object]()
      temp.put("apple", new Double(1));
      // here i received error since double is abstract class and cannot instantitaed
   }
}

我收到的错误是由于抽象 class 实例我想实例化一个整数如何实现这个

如果您想要 scala.Double,请继续阅读。如果你想要 java Double,请参阅 Duelist 的评论

创建一个Double,可以加上小数点,如

1.0

编译器将推断它是 Double。或者,如果您有一个值 val a: Int = 1,您可以提供一个显式类型

a: Double

或转换

a.toDouble

但是,如果您想要一个整数实例(如您所说),则只需使用 1。编译器会推断它是一个 Int