Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

Chapter 24: The Scala Collections API > 24.12 Strings - Pg. 548

C HAPTER 24 · The Scala Collections API 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: scala> def wrap[U: ClassManifest](xs: Vector[U]) = evenElems(xs) wrap: [U](xs: Vector[U])(implicit evidence$1: ClassManifest[U])Array[U] 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] . In summary, generic array creation demands class manifests. Whenever you create an array of a type parameter T , you also need to provide an implicit class manifest for T . The easiest way to do this is to declare the type param- eter with a ClassManifest context bound, as in [T: ClassManifest] . 24.12 Strings Like arrays, strings are not directly sequences, but they can be converted to