add property for a object dynamicly

前端 未结 1 1790
一生所求
一生所求 2021-01-13 22:14

Hi: In our application,we have retrive some data from the database,for example,the table have columes:id,name,age,address,email.

Then we will get some of these prope

相关标签:
1条回答
  • 2021-01-13 22:49

    If I understand you right, you want to dynamically add properties to a class, or rather: to a specific instance of a class.

    The former is possible e.g. in Groovy, where there is a metaclass object for every class, to which you can assign behavior at runtime, the latter is possible in JavaScript, where you can assign behavior both to an object's prototype and to an object itself. But neither of those versions is possible in Java, so using a Map or a similar structure is the thing to do in Java.

    0 讨论(0)
提交回复
热议问题