Possible Duplicate:
How do I invoke a Java method when given the method name as a string?
I have 10 methods named: m1, m2, m3,…
like this:
public void m1(){
..
}
How do I invoke them with string in a ‘for’ loop?
I want to do this:
for (int i=1;i<11;i++){
invoke('m'+i);
}
You need to use
reflectionto achieve this.So, you need to store your method names in an array and use this code piece to call those methods one by one.