In Java, how to get attribute given the string with its name?

前端 未结 5 1064
粉色の甜心
粉色の甜心 2020-12-25 13:51

I\'m sorry for asking this sort of questions, but I really couldn\'t find the answer in Google. So say I have a class with private String myColor and I have a s

5条回答
  •  Happy的楠姐
    2020-12-25 14:10

    If I understand your question correctly... You should create public getters and setters:

    public void setMyColor(String color) {
        this.myColor = color;
    }
    
    public String getMyColor {
        return this.myColor;
    }
    

提交回复
热议问题