Possible Duplicate:
How to dynamically add properties to class
I would like to know is their any way to add fields to my entity class in Java, dynamically, or is their any alternative way of doing this? We are developing a framework and our existing products has this as a requirement.
Example:
class Entity1 {
String name;
String age;
// Getters/setters;
}
Suppose I want to add another field to my Entity1 class (eg: designation), is their any way to add it dynamically/at runtime, so that if my client asks me to add any other properties I can do it with less alteration of code?
Waiting for your reply. Any suggestions are welcome.
You can use javaassist to do this – hibernate use this for a lot of its cool features.
This should help you get started.
You could even use groovy to achieve this so this depends on your preference and any specifics that you may have omitted from the question.