Dynamically Return a Class of a Type Determined During a Method Call via Class.forName()
<p>I know that I can dynamically determine the return type of a method by passing in a class and then declaring that class as the return type, as in the following example:</p>

<pre><code>public static &lt;returnType&gt; returnClass dynamicConstructor (Class&lt;returnType&gt; returnClass){
    //Dynamically construct an object using a zero parameter constructor
    return (returnClass) object;
}
</code></pre>

<p>The code that would be called would be:</p>

<pre><code>DynamicConstructor.construct(constructedClass);
</code></pre>

<p>This code is nice because when you're calling the method in code, it's simple and encapsulated. However, I would like to take it one step further and make the parameter a string containing the full class name, then have the method determine the type of the object via <code>Class.forName(className)</code>. The trouble with this is that I can't figure out how to return the type as determined later on. Using method overloading, the code I have is:</p>

<pre><code>public static ?????? dynamicConstructor (String className){
    try {
        return dynamicConstructor(Class.forName(className));
    } catch (ClassNotFoundException e) {
        System.out.println("Could not find class at path " + classPath);
        e.printStackTrace();
        return null;
    }
}
</code></pre>

<p>The problem is that I have no idea what to put in the part labeled <code>??????</code>. I want to be able to somehow reference the class determined by <code>Class.forName(className)</code>. Is this possible?</p>
