title: Creating objects in java, without knowing the Class at compile time
body: <p>I have a Java question. I have a configuration file that I read and extract some paths to java classes, let's say to an ArrayList of strings (for convenience I will call it <strong>path2libs</strong>).</p>
  
  <p>I want to create an instance for every one of these classes dynamically by iterating this '<strong>path2libs</strong>' array. I tried out something like this:</p>
  
  <pre><code>Class clazz = Class.forName("test.Demo"); 
  Demo demo = (Demo) clazz.newInstance();
  </code></pre>
  
  <p>But I can't know what classes I will read, so I cannot do the appropriate casting.</p>
  
  <p>When this is done, I want to call a method on each object (it is the same method in each case). All of these objects are based on an interface so I know their methods.</p>
  
  <p>So, basically (to summarize) I have two questions :)</p>
  
  <ol>
  <li>Create the desirable objects</li>
  <li>Call a method on each object</li>
  </ol>