问题
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