How to dynamically add properties to class [closed]

孤街醉人 提交于 2019-12-04 01:44:59

问题


I am developing framework for our products. I would like to add dynamically properties to a class. So if any of you have any sort of experience, kindly help me out.

Any of your suggestions are welcome.


回答1:


I believe what you are asking for is not the right option here. Although in theory you can modify the byte code of your program to add a property dynamically as you describe, it is not a good idea at all.

I suggest you use a HashMap that maps a property name to its value and interactively modify that map.



来源:https://stackoverflow.com/questions/14442998/how-to-dynamically-add-properties-to-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!