title: Is there anyway to create a new Scala object from a Java Class
body: <p>I have a number of use cases for this, all around the idea of interop between existing Java libraries and new Scala Code. The use case I've selected is the easiest I think.</p>
  
  <p><strong>Use Case:</strong></p>
  
  <p>I working on providing a JUnit Runner for some scala tests (so that I can get my lovely red / green bar in Eclipse)
  The runner needs to have a constructor with a java class as a parameter. So in Scala I can do the following:</p>
  
  <pre><code>class MyRunner(val clazz: Class[Any]) extends Runner {
    def getDescription(): Description 
    def run(notifier: RunNotifier)
  }
  </code></pre>
  
  <p>When I use either</p>
  
  <pre><code>@RunWith(MyRunner)
  object MyTestObject 
  </code></pre>
  
  <p>or </p>
  
  <pre><code>@RunWith(MyRunner)
  class MyTestClass
  </code></pre>
  
  <p>then the runner is indeed instantiated correctly, and is passed a suitable class object</p>
  
  <p>Unfortunately what i want to do now is to "get hold of" the object MyTestObject, or create a MyTestClass, which are both Scala entities. I would prefer to use Scala Reflection, but I also want to use the standard Junit jar.</p>
  
  <p><strong>What I have done</strong></p>
  
  <p>The following Stackover flow questions were educational, but not the same problem. There were the nearest questions I could find</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/11494788/how-to-create-a-typetag-manually">How to create a TypeTag manually?</a></li>
  <li><a href="https://stackoverflow.com/questions/12901823/any-way-to-obtain-a-java-class-from-a-scala-2-10-type-tag-or-symbol">Any way to obtain a Java class from a Scala (2.10) type tag or symbol?</a></li>
  <li><a href="https://stackoverflow.com/questions/15712097/using-scala-reflection-with-java-reflection">Using Scala reflection with Java reflection</a></li>
  </ul>
  
  <p>The discussion on Environments, Universes and Mirrors in <a href="http://docs.scala-lang.org/overviews/reflection/environment-universes-mirrors.html" rel="nofollow noreferrer">http://docs.scala-lang.org/overviews/reflection/environment-universes-mirrors.html</a> was good, and the similar documents on other scala reflection also helped. Mostly through it is about the Scala reflection. </p>
  
  <p>I browsed the Scaladocs, but my knowledge of Scala reflection wasn't enough (yet) to let me get what I wanted out of them.</p>
  
  <p>Edit:
  As asked here is the code of the class that is being created by reflection</p>
  
  <pre><code>@RunWith(classOf[MyRunner])
  object Hello2 extends App {
  
    println("starting")
  
    val x= "xxx"
  }
  </code></pre>
  
  <p>So the interesting thing is that the solution proposed below using the field called MODULE$ doesn't print anything and the value of x is null</p>