I want to take String Object, which represents the name of a class, then make an Object. If the String is "Mouse" then it will create a new Mouse Object.
This is the Mouse constructor:
public Mouse(int weight){
this.weight = weight;
}
This is what I got so far for my code:
Class<?> c = Class.forName(sub);
Constructor<?> ctorlist[] = c.getDeclaredConstructors();
I don't know how to proceed from here. I checked some websites but they don't make a lot of sense to me. Can someone tell me how to create the object or at least provide a good website with a clear and easy to follow tutorial?
Thanks.
PS. I have to use reflections.