mardi 16 octobre 2018

How to reflect scala class instance?

Assuming the following code:

package my.package

case class ExampleCaseClass(s: String, i: Int, ...)
object ExampleCaseClass {
  val instance = ExampleCaseClass("number", 5, ...)
}

how can I extract class info and data using Scala reflection if the only reference is a string, say my.package.ExampleCaseClass.instance or something along these lines?

In other words, I want to have a function getInfo: String => String which does, say, the following:

getInfo("my.package.ExampleCaseClass.instance") =
  "ExampleCaseClass ( s: number, i: 5, ... )"





Aucun commentaire:

Enregistrer un commentaire