0

Is there any way in Java to create a meta get method that can return any field of the class by using an argument to specify field's name? In other word is there any method in java that can parse values of string variables into variable names. for example some thing like this:

class A{
    private int x;
    private int y;
    public get(String fieldName){
        return evaluate(fieldName); // I am looking for an equivalent to evaluate function that can represent field name (x or y)
    }
} 

Please notice that the evaluate function is not working as it is my question.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Polla A. Fattah
  • 801
  • 2
  • 11
  • 32

0 Answers0