Posted By:
Shridhar_N
Posted On:
Wednesday, October 17, 2001 12:09 AM
Hello Friends I have a Doubt.. In order to use the methods which are there in the ClassLoader class, i need to pass the name of the class as an argument, for this the class should be there in the folder. Can i pass a String as an argument for these methods.. I will have the content of the class in the String. For Ex: String str= "public class hello { public static void main(String args[]) { System.out.println("Hello World"); } public void meth() { System.out.println("Hello"); } }"; Can i pass this String as an argument, and get the instance of the class
More>>
Hello Friends
I have a Doubt..
In order to use the methods which are there in the ClassLoader class, i need to pass the name of the class as an argument, for this the class should be there in the folder.
Can i pass a String as an argument for these methods.. I will have the content of the class in the String.
For Ex: String str=
"public class hello {
public static void main(String args[]) {
System.out.println("Hello World");
}
public void meth()
{
System.out.println("Hello");
}
}";
Can i pass this String as an argument, and get the instance of the class and use that instance for calling meth()...
My ultimate aim is to construct a Class dynamically in a class name MyClass, compile that created MyClass, instantiate that MyClass , and use this instance to call meth(); and after this i will dereference that MyClass....
.Every thing will be Dynamic. , Can we do this,, If Yes Please tell me how to do this with an example......
What i mean is :
String str ="public class hello { public static void main(String args[]) { System.out.println("Hello World"); }public void meth(){System.out.println("Hello");}}";
byte data[] = loadClassData(str);
c = defineClass (str, data, 0, data.length);
Thanks in Advance
Any Suggestions WelCome..
Shridhar..:
<<Less