title: How to instantiate a Scala object using reflection
body: <p>I have some code that uses reflection to instantiate a Java or Scala class, allowing a user to specify the name:
  Assume that <code>loadIt</code> below is a hypothetical method defined using <a href="http://www.javaworld.com/article/2077572/learn-java/java-tip-70--create-objects-from-jar-files-.html#sthash.pgWuhVn3.dpuf" rel="nofollow">this approach</a>.</p>
  
  <pre><code>def getInstance(name:String, jar:String) = {
     val c:Class[_] = loadIt(name, jar) // load class from the jar
     c.newInstance.asInstanceOf[AnyRef] // return new instance of the class
  }
  </code></pre>
  
  <p>This works fine if <code>name</code> is a Scala class, but not if it is an object. 
  Say I define an object:</p>
  
  <pre><code>object Foo
  </code></pre>
  
  <p>and call it as:</p>
  
  <pre><code>getInstance("Foo", "someJar.jar")
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>java.lang.InstantiationException: Foo
      at java.lang.Class.newInstance(Class.java:364)
  </code></pre>
  
  <p>Is there any way I can properly instantiate the object?</p>