I have created a hash table that will keep as a key a string that will represent the name of the method that the user will give, and as value the actual method call, as string too. The code I am using is the one here:
public void getMethod(String givenMethod){
Map<String, String> methods = new HashMap<String, String>();
methods.put("length", "length();");
methods.get(givenMethod);
}
From the main method I call objectX.getMethod(“length”);, but the method length(); is not executed. Can someone help me please?
Use Java **reflection to call method by its name
(as you said you are storing method name in map).
For more detail read following article :
http://java.sun.com/developer/technicalArticles/ALT/Reflection/