Based on another post I am trying to get a companion object for a class given the class name. But I cannot get it to compile:
val clazz = Class.forName(className)
val rootMirror = scala.reflect.runtime.universe.runtimeMirror(clazz.getClassLoader)
val classSymbol = rootMirror.classSymbol(clazz)
val classMirror = rootMirror.reflectClass(classSymbol)
val moduleMirror = classMirror.companion.get
But the last line gives me the following compiler error:
- value companion is not a member of reflect.runtime.universe.ClassMirror
I am using scala version 2.10.4. Orginal post: Get companion object instance with new Scala reflection API