Domanda

I'm migrating from Scala 2.9 to Scala 2.11.0-M5.

Following double field initialization with a constant floating point literal fails.

Code example:

class Test {
  val okDouble = 0.0
  val badDouble = 0.
  val nextValue = 0
}

Scala interpreter error:

scala> class Test {
     |   val okDouble = 0.0
     |   val badDouble = 0.
     |   val nextValue = 0
<console>:4: error: identifier expected but 'val' found.
         val nextValue = 0

The problem here is the dot at the end of badDouble definition.

Should 0.0 be always used for double literals now?

È stato utile?

Soluzione

Double literals ending with dot were deprecated in Scala 2.10 and removed from the language in Scala 2.11:

Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45).

scala> 3.
<console>:1: warning: This lexical syntax is deprecated.  From scala 2.11, a dot
will only be considered part of a number if it is immediately followed by a digit.
       3.
       ^
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top