Returning and instance of a Class given its .class (MyClass.class)
<p>I have an enum that will hold my algorithms.  I cannot instantiate these classes because I need the application context which is only available once the application has started.  I want to load the class at runtime when I choose by calling getAlgorithm(Context cnx).  </p>

<p><strong>How do I easily instantiate a class at runtime given its .class (and my constructor takes arguments)?  All my classes are subclasses of Algorithm.</strong></p>

<pre><code>public enum AlgorithmTypes {
ALL_FROM_9_AND_LAST_FROM_10_ID(AlgorithmFactory.AlgorithmAllFrom9AndLastFrom10Impl.class),
ALL_FROM_9_AND_LAST_FROM_10_CURRENCY_ID(AlgorithmFactory.AlgorithmAllFrom9AndLastFrom10Impl.class),
DIVIDE_BY_9_LESS_THAN_100(AlgorithmFactory.AlgorithmAllFrom9AndLastFrom10Impl.class),
TABLES_BEYOND_5_BY_5(AlgorithmFactory.AlgorithmAllFrom9AndLastFrom10Impl.class);

private Class&lt;? extends Algorithm&gt; algorithm;

AlgorithmTypes(Class&lt;? extends Algorithm&gt; c) {
    algorithm = c;
}

public Algorithm getAlgorithm(Context cnx) {
    return //needs to return the current algoriths constructor which takes the Context Algorithm(Context cnx);
}
</code></pre>

<p>}</p>
