Skip to content
Advertisement

calling numbered function name in loop using java reflection

i have a problem as : MyFirstClass.java

JavaScript

MySecondClass.java

JavaScript

TestClass.java

JavaScript

I want to use java reflection and call the pObj.getP**Param() methods in for loop by providing the parameters to g

JavaScript

How it can be made possible. I don’t want to use array of p*Params.

Thanks in advance.

Advertisement

Answer

Are you sure this is what you need? For me, your code seems to be a typical example of the current trend of abusing reflection for every task. Why don’t you use arrays or maps to store the properties p[0-9]+Param.

Arrays were invented to do exactly that. They provide a range of variables, indexed by numbers.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement