0
scala> Array.fill(3){ math.random }
<console>:6: error: value fill is not a member of object Array
       Array.fill(3){ math.random } 

我在这里错过了什么吗?我无法获得我书中的任何示例,甚至无法从 scala 源代码中编写示例。

Welcome to Scala version 2.7.7final (OpenJDK Server VM, Java 1.6.0_20)
4

1 回答 1

3

因为在 Scala 2.7.7Array中没有fill方法……这已经很老了。您可能应该升级到更新的版本。这是完全相同代码的输出...注意版本:

Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_21).
Type in expressions to have them evaluated.
Type :help for more information.

scala> Array.fill(3){ math.random }
res0: Array[Double] = Array(0.1074472419841086, 0.06627471316010758, 0.08994384621689899)
于 2012-05-29T19:24:58.747 回答