- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
What's the difference between ClassManifest and Manifest?
Tue, 2010-05-04, 08:44
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
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
Wed, 2010-05-05, 06:27
#2
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.ortiz@gmail.com> wrote:
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.ortiz@gmail.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.seeberger@googlemail.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
Wed, 2010-05-05, 07:37
#3
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@gmail.com> wrote:
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@gmail.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.ortiz@gmail.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.seeberger@googlemail.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
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.seeberger@googlemail.com> wrote: