8000 fixed 'res?' console numbering · AYCS/scala.github.com@60681ca · GitHub
[go: up one dir, main page]

Skip to content

Commit 60681ca

Browse files
committed
fixed 'res?' console numbering
1 parent c6d2f45 commit 60681ca

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

overviews/collections/arrays.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ languages: [ja, zh-cn]
1818
scala> val a3 = a2 filter (_ % 2 != 0)
1919
a3: Array[Int] = Array(3, 9)
2020
scala> a3.reverse
21-
res1: Array[Int] = Array(9, 3)
21+
res0: Array[Int] = Array(9, 3)
2222

2323
Given that Scala arrays are represented just like Java arrays, how can these additional features be supported in Scala? In fact, the answer to this question differs between Scala 2.8 and earlier versions. Previously, the Scala compiler somewhat "magically" wrapped and unwrapped arrays to and from `Seq` objects when required in a process called boxing and unboxing. The details of this were quite complicated, in particular when one created a new array of generic type `Array[T]`. There were some puzzling corner cases and the performance of array operations was not all that predictable.
2424

@@ -29,7 +29,7 @@ The Scala 2.8 design is much simpler. Almost all compiler magic is gone. Instead
2929
scala> val a4: Array[Int] = seq.toArray
3030
a4: Array[Int] = Array(1, 2, 3)
3131
scala> a1 eq a4
32-
res2: Boolean = true
32+
res1: Boolean = true
3333

3434
The interaction above demonstrates that arrays are compatible with sequences, because there's an implicit conversion from arrays to `WrappedArray`s. To go the other way, from a `WrappedArray` to an `Array`, you can use the `toArray` method defined in `Traversable`. The last REPL line above shows that wrapping and then unwrapping with `toArray` gives the same array you started with.
3535

0 commit comments

Comments
 (0)
0