Is there a manifest for abstract types like there is for parameterized types?

312 views Asked by At

I wonder if you could write something like the following in Scala:

abstract class Foo

trait Bar {

  type Foo_Tpe <: Foo : Manifest[Foo_Tpe]

  def fooClass = classOf[Foo_Tpe]

}
2

There are 2 answers

0
Daniel C. Sobral On

Yes and no. You can do this:

val man = manifest[Foo_Tpe]

At which point it will tell you it doesn't have a manifest for that.

2
Jean-Philippe Pellet On

No, but you can ask a subclass to provide it:

trait Bar {

  type Foo_Tpe <: Foo

  protected def fooManifest: Manifest[Foo_Tpe]

  def fooClass = fooManifest.erasure

}