I know something is a List[_] based on the Manifest I've passed into a method, but I need to know what kind of item the list is. Is that information stored in the Manifest somewhere and can you get it out? If not, any suggestions about how to work around the issue?
(Basically, I have a Map[Manifest[_], Blah], where Blah handles cases based on the class type. Handling List[X] is composable based on X, but I need to be able to figure out what X is so I can grab its Blah value out of the map.)
Thanks!
I think you're looking for typeArguments
scala> manifest[List[Int]]
res1: Manifest[List[Int]] = scala.collection.immutable.List[Int]
scala> res1.typeArguments
res2: List[scala.reflect.Manifest[_]] = List(Int)
scala> res2.head
res3: scala.reflect.Manifest[_] = Int
scala> res3.erasure
res4: java.lang.Class[_] = int
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With