Why TypeTag doesn't have a runtimeClass method, but Manifest and ClassTag do

I have this code for the general conversion of String to Dto, if I use Manifest and ClassTag, I can use the runtimeClass method to get the execution class, but TypeTag does not have this method

class ObjectMapper[T] { def readValue(x: String, t: Class[T]): T = ??? } class Reader { def read[W: Manifest](x: String): W = { val mapper = new ObjectMapper[W] mapper.readValue(x, implicitly[Manifest[W]].runtimeClass.asInstanceOf[Class[W]]) } } 

May I find out why TypeTag does not have a runtimeClass method

Thank you very much in advance

+5
source share
1 answer

Assuming TypeTag comes from scala.reflect.runtime.universe , you can get the class as follows:

 def runtimeClass(tag: TypeTag) = tag.mirror.runtimeClass(tag.tpe) 

It does not have this method because not all TypeTag are run-time universes.

+6
source

Source: https://habr.com/ru/post/1204556/


All Articles