How can i call a funtion,given its name as string?

Showing Answers 1 - 15 of 15 Answers

sathish

  • Nov 10th, 2006
 

Use reflection API's

  Was this answer useful?  Yes

shiva

  • Nov 11th, 2006
 

satish explain it, i dont understand

  Was this answer useful?  Yes

nagu

  • Dec 18th, 2006
 

   Class clsObj = Class.forName("ClassName");
   Method method = clsObj.getMethod("methodName",null);
   method.invoke(clsObj.newInstance(),null);

we can also call the method using Introspection API, Eclipse uses this API to get the name of all the methods available in a class after we enter "." after a Class Instance or Class Name for static methods;

  Was this answer useful?  Yes

sampra

  • Mar 10th, 2008
 

Class clsObj = Class.forName("ClassName");
   Method method = clsObj.getMethod("methodName",null);
   method.invoke(clsObj.newInstance(),null);

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions