samedi 7 février 2015

Scala: How to get a Class[_] instance out of Type?

I'm implementing deep runtime reflection. Given a universe.Type, can I get runtime class instance for the type? ClassTags won't help me as they lose type parameter information. Given the following classes:



case class One[T](item :T)
case class Parent(id :Long)
case class Child(id :Long, parent :One[Parent])


When given typeTag (and possibly classTag) of Child, I wan't to be able to determine, that parent.value runtime class should be Class[Parent]. Of course, I want it to work recursively for more complex examples.






Aucun commentaire:

Enregistrer un commentaire