-1
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
   }
}

Error i received was due to abstract class instance i want to instance a integer how to achieve this

  • 2
    If you wanted to pass Java's class Double you should change it like so: `new Double(1)` to `new java.lang.Double(1)` – Duelist Jul 23 '18 at 11:11

1 Answers1

2

if you want a scala.Double, read on. If you want a java Double, see Duelist's comment

To create a Double, you can add the decimal point, as

1.0

where the compiler will infer it's a Double. Or, if you have a value val a: Int = 1, you can provide an explicit type as

a: Double

or convert

a.toDouble

However, if you want an integer instance (as you said), then just use 1. The compiler will infer it's an Int

Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93
joel
  • 6,359
  • 2
  • 30
  • 55