我正在从Scala 2.9迁移到Scala 2.11.0-M5。
使用常量浮点文字进行双字段初始化失败。
代码示例:
class Test {
val okDouble = 0.0
val badDouble = 0.
val nextValue = 0
}
Scala解释器错误:
scala> class Test {
| val okDouble = 0.0
| val badDouble = 0.
| val nextValue = 0
<console>:4: error: identifier expected but 'val' found.
val nextValue = 0
这里的问题是badDouble定义结尾处的点。
现在应该总是将0.0用于双重文字吗?
答案 0 :(得分:1)
在Scala 2.10中不推荐使用以dot结尾的双重文字,并从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.
^