Scala Array map returns ArraySeq

后端 未结 1 1432
逝去的感伤
逝去的感伤 2021-01-18 05:33

Why can\'t I have type parameters in my factory methods below?

import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.Fu         


        
相关标签:
1条回答
  • 2021-01-18 06:36

    Just add ClassManifest context bound:

        def apply[T, U: ClassManifest](arr: Array[T], f: T => U): Bucket[U] = new Bucket[U](arr.map(b => f(b)))
        def apply[T: ClassManifest](arr: Array[String], f: String => T): Bucket[T] = new Bucket[T](arr.map(b => f(b)))
    

    For details check this and this

    0 讨论(0)
提交回复
热议问题