I would like to be able to get an instance of a Scala Object from a String specified in config. Say for example I have a config property db.driver = "scala.slick.driver.H2Driver"
I would like to be able to get an instance of this object H2Driver
. Obviously I could create a map of configs to actual objects, but that seems like a hassle. I could also do this by including a $ on the end of the config and loading up the module, i.e.
val cl = Class.forName("scala.slick.driver.H2Driver$") //note the $
val driverObj = cl.getField("MODULE$").get(null).asInstanceOf[JdbcProfile]
But I was hoping there was a neater way to do this in Scala 2.10 using the newer reflections API.