8000 Array -> Vector · codeZeilen/scala.github.com@34d57c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 34d57c6

Browse files
committed
Array -> Vector
1 parent 026ac09 commit 34d57c6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

overviews/collections/arrays.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ Here is some REPL interaction that uses the `evenElems` method.
103103

104104
In both cases, the Scala compiler automatically constructed a class manifest for the element type (first, `Int`, then `String`) and passed it to the implicit parameter of the `evenElems` method. The compiler can do that for all concrete types, but not if the argument is itself another type parameter without its class manifest. For instance, the following fails:
105105

106-
scala> def wrap[U](xs: Array[U]) = evenElems(xs)
106+
scala> def wrap[U](xs: Vector[U]) = evenElems(xs)
107107
<console>:6: error: could not find implicit value for
108108
evidence parameter of type ClassManifest[U]
109-
def wrap[U](xs: Array[U]) = evenElems(xs)
109+
def wrap[U](xs: Vector[U]) = evenElems(xs)
110110
^
111111

112112
What happened here is that the `evenElems` demands a class manifest for the type parameter `U`, but none was found. The solution in this case is, of course, to demand another implicit class manifest for `U`. So the following works:
113113

114-
scala> def wrap[U: ClassManifest](xs: Array[U]) = evenElems(xs)
115-
wrap: [U](xs: Array[U])(implicit evidence$1: ClassManifest[U])Array[U]
114+
scala> def wrap[U: ClassManifest](xs: Vector[U]) = evenElems(xs)
115+
wrap: [U](xs: Vector[U])(implicit evidence$1: ClassManifest[U])Array[U]
116116

117117
This example also shows that the context bound in the definition of `U` is just a shorthand for an implicit parameter named here `evidence$1` of type `ClassManifest[U]`.
118118

0 commit comments

Comments
 (0)
0