Archived

This topic is now archived and is closed to further replies.

[java] ClassLoader

This topic is 5771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been experimenting with the ClassLoader, and everything seems to work up to the point where I have a Class object of my newly loaded .class file. This is the class I''m loading; public class Tester { public void doSomething() { System.out.println("w00t"); } } If newclass is the Tester class I just loaded, how do I call doSomething() from ''o''? Object o = newclass.newInstance(); //o.doSomething()

Share this post


Link to post
Share on other sites
quote:
Original post by Redferne
The class is loaded at runtime, so the name of the class can''t be hardcoded (because it could be called anything)

Since the name of the method you are calling is obviously hardcoded, have the class you load implement an interface with the appropriate method and cast to that.



The world holds two classes of men -- intelligent men without religion, and religious men without intelligence. Abu''l-Ala-Al-Ma''arri (973-1057; Syrian poet)

Share this post


Link to post
Share on other sites
thanks Pepe, I had been trying to cast it to a superclass that defined the same method, but I couldn't get it to work. Your suggestion works great however, thanks again

Edited by - Redferne on February 23, 2002 4:09:41 AM

Share this post


Link to post
Share on other sites