Is it possible to get a reference to a Scala Object class from Java, using reflection?
To illustrate what I mean, this is the Scala code for doing this (assume MyClass is a Scala Object):
val runtimeMirror = universe.runtimeMirror(getClass.getClassLoader)
val module = runtimeMirror.staticModule("MyClass")
val obj = runtimeMirror.reflectModule(module)
val realObject: MyInterface = obj.instance.asInstanceOf[MyInterface]
In Java, I successfully loaded the Class, but I can't seem to be able to get an actual reference to the object; calling newInstance() on the class obviously fails since it doesn't have a public constructor.
I've managed to workaround it by getting its constructor by reflection and setting it to be accessible, but that seems like a hack to me.. is there a BKM for doing this sort of thing?