How to add attributes Dynamically for java object?

前端 未结 4 412
清歌不尽
清歌不尽 2020-12-15 01:27

Having Student Class.

Class Student{
    String _name;
    ....
    ....

    public Student(){
    }
}

is there any possibility to add dyn

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-15 01:56

    Although you can do that with some tricky, and complex way that others have suggested..

    But you can sure have your attributes in some data structure(An appropriate one will be a Map).. Since you can modify your existing attributes, so can be done with you Data Structure. You can add more attributes to them.. This will be a better approach..

提交回复
热议问题