Reputation: 1651
I am trying to instatiate a class from a String using:
Class configClass = Class.forName(configClassName);
Class testClass = Class.forName(className);
Constructor constr = testClass.getConstructor(configClass);
TestCase testCase = (TestCase) constr.newInstance(configClass);
The constructor in the class RecursiveLinkTest that extends TestCase looks like this:
public RecursiveLinkTest(Class<JsonConfig> configClass)
As you can see the parameter in RecursiveLinkTest is of the typ Class. How can i get the constructor for the class? I am getting NoSuchMethodException when I run my code. (It can create the Class objects configClass and testClass).
Upvotes: 0
Views: 28
Reputation: 9100
I think this will solve your problem:
Constructor constr = testClass.getConstructor(Class.class);
You need to get the constructor with the Class as the argument.
Upvotes: 1