vendredi 27 février 2015

how to get name and value of each parametes in java method?

I would like to get the name of each parameter and value coming to my method in java. I searched about it but I could not find something to help me. Can you show me a solution. I have a method as below



public HashMap<String, Object> putallinMap(Object...pars){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(pars[0].{name}, pars[0].{value});
return map;
}


This is How I call the method above.



String str1 = "Hello world!";
int myint = 55;
double myDouble = 11.5;
...// there can be other primitive types, long, short, Double etc.

HashMap<String, Object> map attrInMap = putallinMap(str1, myint, myDouble);


Sow What I expect to have a hasmap like below.



{"str1":"Hello world!", "myint" : 55, "myDouble": 11.5}





Aucun commentaire:

Enregistrer un commentaire