This page is no longer maintained — Please continue to the home page at www.scala-lang.org

What's the difference between ClassManifest and Manifest?

3 replies
hseeberger
Joined: 2008-12-27,
User offline. Last seen 1 year 25 weeks ago.
Hi,
could someone please explain the difference between ClassManifest and Manifest? And when to use which one?
Thanks,

Heiko

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org
Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 4 days ago.
Re: What's the difference between ClassManifest and Manifest?
My understand is that if:
  type T = Foo[Bar[Baz]]
then Manifest[T] represents the entire Foo[Bar[Baz]] type, whereas ClassManifest[T] only represents Foo[_].
For instantiating Arrays, you only need to know whether it's a primitive array or a reference array, so only the ClassManifest is needed. (But a Manifest is also a ClassManifest...)
--j
On Tue, May 4, 2010 at 12:44 AM, Heiko Seeberger <heiko [dot] seeberger [at] googlemail [dot] com> wrote:
Hi,
could someone please explain the difference between ClassManifest and Manifest? And when to use which one?
Thanks,

Heiko

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org

Arjan Blokzijl
Joined: 2009-10-31,
User offline. Last seen 46 weeks 5 days ago.
Re: What's the difference between ClassManifest and Manifest?
That's what I understood from the Array SID as well, and the code also seemed to indicate this. However, a brief experiment in the REPL showed this:
scala> class Foo[T] defined class Foo
scala> class Bar[T] defined class Bar
scala> class Baz defined class Baz
scala> type T = Foo[Bar[Baz]]  defined type alias T
scala>val m = manifest[T] m: Manifest[T] = Foo[Bar[Baz]]
scala> val cm = classManifest[T]cm: ClassManifest[T] = Foo[Bar[Baz]]
scala> m.typeArgumentsres0: List[scala.reflect.Manifest[_]] = List(Bar[Baz])
scala> cm.typeArgumentsres1: List[scala.reflect.OptManifest[_]] = List(Bar[Baz])
scala> cm == mres2: Boolean = true
scala> cm.isInstanceOf[Manifest[_]] res3: Boolean = false
scala> m.isInstanceOf[Manifest[_]]  res4: Boolean = true
scala> cm.isInstanceOf[ClassManifest[_]] res5: Boolean = true

Perhaps I'm doing the completely wrong experiment here, but at first sight the ClassManifest also seems to contain all type arguments.

Arjan

On Tue, May 4, 2010 at 7:13 PM, Jorge Ortiz <jorge [dot] ortiz [at] gmail [dot] com> wrote:
My understand is that if:
  type T = Foo[Bar[Baz]]
then Manifest[T] represents the entire Foo[Bar[Baz]] type, whereas ClassManifest[T] only represents Foo[_].
For instantiating Arrays, you only need to know whether it's a primitive array or a reference array, so only the ClassManifest is needed. (But a Manifest is also a ClassManifest...)
--j
On Tue, May 4, 2010 at 12:44 AM, Heiko Seeberger <heiko [dot] seeberger [at] googlemail [dot] com> wrote:
Hi,
could someone please explain the difference between ClassManifest and Manifest? And when to use which one?
Thanks,

Heiko

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org


Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 4 days ago.
Re: What's the difference between ClassManifest and Manifest?
Yes, you're correct. I see now that ClassManifest captures as much type information as it can.
The difference comes here:
scala> class Foo[T]defined class Foo
scala> type T = Foo[_]defined type alias T
scala> val m = manifest[T]<console>:6: error: could not find implicit value for parameter m: Manifest[T]        val m = manifest[T]                       ^
scala> val m = classManifest[T]m: ClassManifest[T] = Foo[<?>]
In this case, you can make a ClassManifest[T], but you can't make a Manifest[T].
--j
On Tue, May 4, 2010 at 10:19 PM, Arjan Blokzijl <arjanblokzijl [at] gmail [dot] com> wrote:
That's what I understood from the Array SID as well, and the code also seemed to indicate this. However, a brief experiment in the REPL showed this:
scala> class Foo[T] defined class Foo
scala> class Bar[T] defined class Bar
scala> class Baz defined class Baz
scala> type T = Foo[Bar[Baz]]  defined type alias T
scala>val m = manifest[T] m: Manifest[T] = Foo[Bar[Baz]]
scala> val cm = classManifest[T]cm: ClassManifest[T] = Foo[Bar[Baz]]
scala> m.typeArgumentsres0: List[scala.reflect.Manifest[_]] = List(Bar[Baz])
scala> cm.typeArgumentsres1: List[scala.reflect.OptManifest[_]] = List(Bar[Baz])
scala> cm == mres2: Boolean = true
scala> cm.isInstanceOf[Manifest[_]] res3: Boolean = false
scala> m.isInstanceOf[Manifest[_]]  res4: Boolean = true
scala> cm.isInstanceOf[ClassManifest[_]] res5: Boolean = true

Perhaps I'm doing the completely wrong experiment here, but at first sight the ClassManifest also seems to contain all type arguments.

Arjan

On Tue, May 4, 2010 at 7:13 PM, Jorge Ortiz <jorge [dot] ortiz [at] gmail [dot] com> wrote:
My understand is that if:
  type T = Foo[Bar[Baz]]
then Manifest[T] represents the entire Foo[Bar[Baz]] type, whereas ClassManifest[T] only represents Foo[_].
For instantiating Arrays, you only need to know whether it's a primitive array or a reference array, so only the ClassManifest is needed. (But a Manifest is also a ClassManifest...)
--j
On Tue, May 4, 2010 at 12:44 AM, Heiko Seeberger <heiko [dot] seeberger [at] googlemail [dot] com> wrote:
Hi,
could someone please explain the difference between ClassManifest and Manifest? And when to use which one?
Thanks,

Heiko

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org



Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland