I have a map containing the fields of a case class I would to create. I don't want to only instantiate the class, I want to create it from scratch and use it at run time. The class I want to create will only contains fields (no methods).
One of my first was to interpret code at runtime that would return this new class from string interpretation. We can do something like this with toolBox:
import scala.reflect.runtime._
import scala.tools.reflect.ToolBox
val cm = universe.runtimeMirror(getClass.getClassLoader)
val tb = cm.mkToolBox()
val myClass = tb.eval(tb.parse("class C(val a:Int, val b:Int); scala.reflect.classTag[C].runtimeClass"))
I found the code here. But I don't know what to do after. I have the myClass object which seems to be a java.lang.Class. Since the code line:
println(myClass.getClass.getName)
returns:
java.lang.Class
What should I do after?
Would I manage to do what I want with this?
If no what are the others possibility.