I need the object (or “singleton object” or “companion object”… anything but the class) defined by a string name. In other words, if I have:
package myPackage
object myObject
…then is there anything like this:
GetSingletonObjectByName("myPackage.myObject") match {
case instance: myPackage.myObject => "instance is what I wanted"
}
Scala is still missing a reflection API. You can get the an instance of the companion object by loading the companion object class:
To get the untyped companion object you can use the class directly:
This depends on the way scala is mapped to java classes.