Reputation: 16387
Is it possible to get the type parameters of a manifest type included in the class object.
I might not be describing that correctly, so what I mean is, given this type.
Resultset[Band[Coldplay]]
I want a manfiest that represents the full type, so that it should be possible to get a class instance that has the type
Class[Resultset[Band[Coldplay]]]
All I can get is
Class[Resultset[_]]
Upvotes: 2
Views: 145
Reputation: 167871
You could build a manifest into a class:
case class Manifesting[A](value: A)(implicit val mf: Manifest[A]) { }
scala> Manifesting(5).mf.erasurescala> Manifesting(5).mf.erasure
res1: Class[_] = int
Or you can build all the manifests into a method:
def nested[A, B[A]](x: B[A])(implicit ma: Manifest[A], mb: Manifest[B[A]]) =
(ma.erasure, mb.erasure)
scala> nested(List("fish"))
res2: (Class[_$1], Class[_$1]) forSome { type _$1; type _$1 } =
(class java.lang.String,class scala.collection.immutable.List)
Or, in Scala 2.10 you can use TypeTag
:
def nest2[A: scala.reflect.runtime.universe.TypeTag](x: A) =
implicitly[scala.reflect.runtime.universe.TypeTag[A]]
scala> nest2(Right(List("salmon","herring")))
res3: reflect.runtime.universe.TypeTag[scala.util.Right[Nothing,List[String]]] =
TypeTag[scala.util.Right[Nothing,List[String]]]
Upvotes: 4