i have class something like this
class MClass
{
private int mem1,mem2,mem3.......;
public int getmem1()
{
return mem1;
}
public int getmem2()
{
return mem2;
}
......
Now I want something like this :
public int getAttr(String attr)
{
if (attr=="mem1")
return mem1;
elseif (attr=="mem2")
return mem2;
.....
How do I implement getAttr for 1000s of attr ?
Please don’t ask me to make mem as array.. that is not possible due to other parts of program.
Use reflection. Reflection
This will allow you to call any public method at runtime using the name of the method as a String.