Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Creating objects with relfections

840446Apr 26 2011 — edited Apr 26 2011
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.
This post has been answered by baftos on Apr 26 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 24 2011
Added on Apr 26 2011
3 comments
138 views