java - add property for a object dynamicly -


hi: in our application,we have retrive data database,for example,the table have columes:id,name,age,address,email.

then of these propertis according client.

if client need id, name, id name, if client need id, name, age, id, name, age.

now want create class wrap these properties. not know field requested.

string[] requestpro={"name","id"}; //this field specified client map<string, object> map=new hashmap<string, object>(); entity en=entity.newinstance(); for(string p:requestpro){     map.put(p, beanutils.getproperty(en, p)); } 

here can replace map class?

if understand right, want dynamically add properties class, or rather: specific instance of class.

the former possible e.g. in groovy, there metaclass object every class, can assign behavior @ runtime, latter possible in javascript, can assign behavior both object's prototype , object itself. neither of versions possible in java, using map or similar structure thing in java.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -