Reputation: 65
I need to call some functions generated by some libs. I will need to call fucntion1
, function2
, ..., function10
one by one. Instead of writing them all out on the code, is there any clever way to code it?
Upvotes: 2
Views: 117
Reputation: 2637
You could also use the Expression class from java.beans package
http://download.oracle.com/javase/6/docs/api/index.html?java/beans/package-summary.html
construct a expression object.
Expression(Object target,String methodName,Object[] arguments)
and then on the expression object you can use getValue()
Cheers!
Upvotes: 1
Reputation: 1108702
You could use reflection.
Some some = new Some();
for (int i = 1; i <= 10; i++) {
some.getClass().getMethod("function" + i).invoke(some);
}
Upvotes: 7