lundi 25 juin 2018

How to reflectively parameterise a generic type in Scala?

How can I implement the following psuedocode in Scala using reflection?

trait Foo[A]

def parameterizeFoo(param: Class[_]): Class[_] = ???

assert(parameterizeFoo(classOf[Int]) === classOf[Foo[Int]])

Note: I do not have access to the type of A at compile time, hence the _. The entire solution needs to be performed reflectively (e.g. I cannot have parameterizeFoo[A : ClassTag](...)).





Aucun commentaire:

Enregistrer un commentaire