title: Using reflection in Java to create a new instance with the reference variable type set to the new instance class name?
body: <p>All the examples I look at for reflection show creating a new instance of an unknown implementation, and casting that implementation to it's interface. The issue with this is that now you can't call any new methods (only overrides) on the implementing class, as your object reference variable has the interface type. Here is what I have:</p>
  
  <pre><code>Class c = null;
  try {
      c = Class.forName("com.path.to.ImplementationType");
  } catch (ClassNotFoundException e) {
      e.printStackTrace();
  }
  InterfaceType interfaceType = null;
  try {
      interfaceType = (InterfaceType)c.newInstance();
  } catch (InstantiationException e) {
      e.printStackTrace();
  } catch (IllegalAccessException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>If I only have a reference to "com.path.to.ImplementationType", and I don't know what that type might be (it is coming from a config file), then how can I use the class name to cast it to ImplementationType? Is this even possible?</p>