I have a class
class JsonMap extends HashMap<String, Object> {}
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?
you would need to write methods to do this for you