mardi 18 août 2015

Java Dynamic Function Call

I have a class
class JsonMap extends HashMap {}

I initialized an object like this
JsonMap jm = new JsonMap();

I am inserting data into it like this
jm.put("id", 4);
jm.put("message", "Hello");

but i want to do something easy like this with same effect.
jm.setId(4);
jm.setMessage("Hello");

Is this possibe without having to write methods setId and setMessage in JsonMap class?
function name is dynamic: first part is always 'set' and second part is dynamic value. this will go as key inside HashMap.
Can anyone show me how to achieve this, if it's possible?

Thank you!




Aucun commentaire:

Enregistrer un commentaire