I need a little bit of help here, tell me if you have any idea how to solve my problem.
Let's say i have this class :
public testClass{
public int example1(){
return 2;
}
public int example2(){
return 0;
}
public int example3(){
return 456;
}
}
I want a method which will do the same thing that this method, but in a dynamic way
public int methodeSwitch(int a){
if (a==1){return method1;}
if (a==2){return method2;}
if (a==3){return method3;}
return null;
}
My problem is that I have a huge class (dto) with 50+ fields, so i'd like to use getters and setters depending on the fields that i use at the moment (so yeah, dynamically). I know how to access fields (with java.lang.Field, wouuu), but i have no clue on how I could cast a method by its name (which will be created dynamically).
Just giving me a hint would be amazing!
Thanks Fabien
EDIT: to clarify, I have to write a method who basically use every setters of my class, so if I could use something like
useMethod("set"+fields[i]+"();");
That would be helpful and prevent me from writing dozens of lines of code.
Thanks again for the ones helping! ;)
example1()etc defined?return method1? call method1 or is it a field