基于另一篇文章,我试图获得一个给定类名的类的伴随对象。但我无法编译:
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
但最后一行给出了以下编译器错误:
- value companion is not a member of reflect.runtime.universe.ClassMirror
我正在使用scala版本2.10.4。原始帖子:Get companion object instance with new Scala reflection API