How to access a Scala object instance given its full qualified name?
04:19 28 Aug 2018

So I have defined a Scala object using the following code:

trait SomeTrait {
  def someMethod(): Unit
}

package somepackage1 {
  object Impl1 extends SomeTrait {
    def someMethod(): Unit = { }
  }
  object Impl2 extends SomeTrait {
    def someMethod(): Unit = { }
  }
}

I want to access the object given its fully qualified name i.e. somepackage1.Impl2. A method something like following:

package object somewhereElse {
  def getImpl(qualifiedName: String): SomeTrait = {
    ???
  }
}

What should be the code as part of getImpl method?

scala reflection singleton companion-object