3
scala> def a[A](b:Seq[A]) = b.toArray
<console>:7: error: could not find implicit value 
                    for evidence parameter of type ClassManifest[A]
       def a[A](b:Seq[A]) = b.toArray
                              ^

What is the problem here? And how can I work around this?

3 Answers 3

6

What you have to do is to specify the returnable type, this will work (for scala < 2.8):

def a[A](b:Seq[A]):Array[A] = b.toArray

Due to the new Collections framework which had to do special kind of conversion in order to handle Arrays like Collections see Fighting bit rot page 448, we have to tell about the high-order type, and it's the meaning of ClassManifest which tells about the class (there is a Manifest that is wider).

So both examples below are valid (more information here Collections API Explained):

 def a[A](b:Seq[A])(implicit m:ClassManifest[A]):Array[A] = b.toArray

 def a[A:ClassManifest](b:Seq[A]):Array[A] = b.toArray
Sign up to request clarification or add additional context in comments.

1 Comment

So I added for >= 2.8, and why it should be given such weird extra information to the compiler
4
scala> def a[A : ClassManifest](b:Seq[A]) = b.toArray
a: [A](b: Seq[A])(implicit evidence$1: ClassManifest[A])Array[A]

scala>

Comments

3

You need to add a view bound to provide it with the manifest:

def a[A: ClassManifest](b:Seq[A]) = b.toArray

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.