2

I am new to Scala and I was learning "context bound" from posts. But I found many of those are explaining "context bound" using ClassManifest as example. For instance,

def tabulate[T](len: Int, f: Int => T)(implicit m: ClassManifest[T]) = {
    val xs = new Array[T](len)
    for (i <- 0 until len) xs(i) = f(i)
    xs
}

I find it weird that the implicit parameter m is required but never used in the function body. Thus I would like to know what ClassManifest is and what its relationship is with context bound. Thanks!

EDIT:

I have seen What is a Manifest in Scala and when do you need it? before, but it's asking for Manifest not ClassManifest, and there is no explanation regarding ClassManifest in that post, thus I ask this similar (but, IMO, not duplicate) question.

Community
  • 1
  • 1
Lifu Huang
  • 11,930
  • 14
  • 55
  • 77
  • 3
    Possible duplicate of [What is a Manifest in Scala and when do you need it?](http://stackoverflow.com/questions/3213510/what-is-a-manifest-in-scala-and-when-do-you-need-it) – manojlds Sep 14 '16 at 09:18
  • @manojlds Sorry I am new to Scala, but is `Manifest` the same thing as `ClassManifest`? Thanks – Lifu Huang Sep 14 '16 at 09:27
  • please note that both are deprecated – dk14 Sep 14 '16 at 10:14

1 Answers1

3

You can find explanation about ClassManifest for old scala versions (before 2.10) here. Please, read all answers, some of them explain not only Manifest but ClassManifest too:

There exists also a weaker form named ClassManifest which can be constructed from knowing just the top-level class of a type, without necessarily knowing all its argument types.

In Scala 2.11.8, 2.12-M4 ClassManifest is deprecated and became an alias to ClassTag :

type  ClassManifest[T] = ClassTag[T]

It's deprecated since 2.10.0.

P.S. Actually this post from scala documentation that you probably read is completely outdated, even the view bounds (<%) described there are deprecated too (for a quite long time) so you should avoid them as well (using this simple trick if you really need them, but implicit views are not recommended in any form)

Community
  • 1
  • 1
dk14
  • 22,206
  • 4
  • 51
  • 88