0

I've been googling hours about scala type classes but I still can't figure out how to solve this problem:

 def mkArray[A:Ordering](size:Int):Array[A] = {
    Array.ofDim[A](size)
 }

Basicly my problem was that I couldn“t create an array of type A:Ordering, so I tried bunch of things and ended up using function above. But it tells me that:

- not enough arguments for method ofDim: (implicit evidence$3: scala.reflect.ClassTag[A])Array[A]. Unspecified value parameter 
 evidence$3.
- No ClassTag available for A

So if you could tell me how to get around this problem and perhaps explain a bit whats going on in here, it would be much appreciated!

Ou Tsei
  • 470
  • 7
  • 24

1 Answers1

0

Array.ofDim requires implicit ClassTag for T in scope, so you need to add it to your mkArray function

  def mkArray[A:Ordering:ClassTag](size:Int):Array[A] = {
    Array.ofDim[A](size)
  }

  mkArray[String](10)
Eugene Zhulenev
  • 9,714
  • 2
  • 30
  • 40