Java classes with dynamic fields

后端 未结 5 729
孤独总比滥情好
孤独总比滥情好 2021-02-06 10:55

I\'m looking for clever ways to build dynamic Java classes, that is classes where you can add/remove fields at runtime. Usage scenario: I have an editor where users should be ab

5条回答
  •  死守一世寂寞
    2021-02-06 11:05

    I do almost the same, it's pure Java solution:

    1. Users generate their own models, which are stored as JAXB schema.
    2. Schema is compiled in Java classes on the fly and stored in user jars
    3. All classes are forced to extend one "root" class, where you could put every extra functionality you want.
    4. Appropriate classloaders are implemented with "model change" listeners.

    Speaking of performance (which is important in my case), you can hardly beat this solution. Reusability is the same of XML document.

提交回复
热议问题