• Post Reply Bookmark Topic Watch Topic
  • New Topic

convert a string variable to a function call

 
varkala prabhakar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai all,
i will be calling a member function using the function
xyz("insert","insert_fun()");
i have a member function accepts two strings say
public void xyz(String arg1, String arg2){
}

Coulds any one help me how to use the string variable in the xyz function to call the insert_fun() in xyz function.
thanx
prabhakar.
 
David Meyers
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know of no way of doing what you are asking. How many different methods may you be calling? If there aren't that many you have several options.
A) If only 2 choices pass a boolean and call the proper methd based on this parameter.
B) If many choices pass an int and create an Interface with constants where numbers stand for a method. Then use a switch statement in your method to call other methods based on this parameter.
If neither of those solutions will work, perhaps a little more info on what you are trying to do would help.
Good luck,
Dave
 
James Swan
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need to check out the reflection APIs.
Have a look at this link: http://www.javaranch.com/ubb/Forum50/HTML/000081.html
 
varkala prabhakar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai David and swam,
I will try with the solutions u suggested me
thanx a lot
prabhakar.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!