case class Thing[T](value: T)
def processThing(thing: Thing[_]) = {
thing match {
case Thing(value: Int) => "Thing of int"
case Thing(value: String) => "Thing of string"
case _ => "Thing of something else"
}
}
println(processThing(Thing(1)))
println(processThing(Thing("hello")))
Above outputs Thing of int and Thing of string. My question is why the type info
is still available in runtime if type eraser kicks in?
This is not when type erasure kicks in, if you try this:
You will get
Thing of int. Withcase Thing(value: Int)you're basically doing a pattern matching with type assertion, I think it would be something like this: