How to Creating an instance of a class from string i.e.class name will be passed as string and also want to call methods (methods do not have any parameters).
for example with class name TEST having methods like 1) GetData 2) GetAddtionof2numbres etc...
i want to pass class name TEST using a variable.
String className = "TEST";
i have tried with refection i.e using as below
Class cls = Class.forName(className);
object o = cls.newinstance();
but not able to get/access methods in that class.
when i get method names from the class i will compare them with the names stores in text files and run that method in that class by creating an instance of the class at run time.
Can any body help me in this
thanks in advance
i have tried with below
String className = "test.t456";
Class c = Class.forName(className);
Object obj = c.newInstance();
Method[] method = c.getDeclaredMethods();
for(Method m : method)
{
System.out.println(m.getName());
}
able to print method names in console. Now how to run these methods by creating instance of that class.?