Could not find implicit value for evidence parameter of type scala.reflect.ClassManifest[T]

前端 未结 2 1495
庸人自扰
庸人自扰 2021-02-12 14:24

It seems I don\'t understand something important, maybe about erasure (damn it).

I have a method, which I wanted to create array of size n filled with value

2条回答
  •  离开以前
    2021-02-12 14:43

    That is because in testArray the concrete type of T is not known at compile time. Your signature has to look like def testArray[T : ClassManifest](n: Int, gen: =>T), this will add an implicit parameter of type ClassManifest[T] to your method, that is automatically passed to the call of testArray and then further passed to the Array.fill call. This is called a context bound.

提交回复
热议问题