Jump to content
  • Advertisement

Archived

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

Redferne

[java] ClassLoader

This topic is 6054 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
Advertisement
Look classes at package java.lang.reflect

In particular java.lang.reflect.Method

Everybody of us who like code in C++ would like these were part of it.

Share this post


Link to post
Share on other sites
Hey Redferme

Edit your profile,
click View Your Profile anchor,
look at the other thread you have participated.

There is the same response I tell you in my previous reply

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!