[java] ClassLoader
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()
The class is loaded at runtime, so the name of the class can''t be hardcoded (because it could be called anything)
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.
In particular java.lang.reflect.Method
Everybody of us who like code in C++ would like these were part of it.
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
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
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)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement