Consider the following attempt that doesn't quite work
public void createClass() {
try {
MyClass b = (MyClass)getMyClassType().newInstance();
} catch(Exception e) {
e.printStackTrace();
}
}
public Class<?> getMyClassType() {
MyClass a = new MyClass(1);
return a.getClass();
}
public class MyClass {
private int k = 0;
public MyClass(int t) {
k = t;
}
}
The above gets
Caused by: java.lang.NoSuchMethodException
I am not quite sure why it doesn't work.
Essentially I want to be able to create class from class type, preferably something like this
Map<String, ClassType> a = new HashMap<>()
a.get("myClassName").createClassInstanceFromClassType(constructorParam1);
Is the above possible in java?