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

345 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 best solutions below

0
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
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

}