Dynamic Methods Selection
Posted on 2000-01-17
I would like to write a class that allow user to enter key no. to activate the methods selected, do you think it is possible?
I declare an ArrayList containing names string of methods: "method1", "method2", "method3".
ArrayList aList = new ArrayList() ;
All the three methods got same interface, but different function.For eg.
public byte method1(int data)
Can I select the method by this way:
public byte selectMethod(int ID, int data)
byte result = ((aList.get(ID)(data)) ;
return result ;
I got error when compiling, ')' expected.
Do you know ways to dynamically select the functions, apart from using if-else or switch-cast? As the list of methods, I hope to make it dynamic, that is the no. of methods might be changed in future. and might be downloaded from the server etc.
Please advise...Thank you very much...