vendredi 19 février 2016

Get arguments of optional object instances in Scala using run time reflection

I have the following class, which I cannot modify

class A {
val x = new B ( () => new CC, () => new CB )   
}

The two arguments to class B vary by class name for each program. Also sometimes there is no instantiation of class B under class A. My goal is get class name of the arguments as strings. In this example I extract two strings CC and CB.

Initial approach of using ClassTag works as long as there is an object for class B, but if there is none, whole compilation fails

I tried to use run-time reflection as follows

typeOf[B[_,_]].members.filter(_. isPrivate)

But not able to get arguments as strings. Thanks in advance





Aucun commentaire:

Enregistrer un commentaire