Skip to Main Content

Java Programming

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!

Create instance of a class based upon string or class

807588Jun 22 2009 — edited Jun 22 2009
Say i have this:

MyClass aClass = new MyClass();

MyClass extends MySuper.

Somewere i have a procedure

public MySuper createNew()

How should i implement createNew so i can pass for example "MyClass" or aClass so that function will return the correct type?

For example:

MyClass aClass = someClass.createNew("MyClass");
or
MyClass aClass = new MyClass();
MyClass another = someClass.createNew(aClass);
or
MyClass aClass = someClass.createNew(MyClass);

If one of those 3 possible or should i use something else to get this working?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 20 2009
Added on Jun 22 2009
5 comments
87 views