I need to store variable and value as a pair somewhere and I tend to use Map. The problem is the type of value would be different so I think generic should be used. So I tried something like this:
Map<String, T> netPara;
and of course it does not work, then I tried
Map<String, Object> netPara;
This worked but when I retrived value it returned only of type Object, instead of "boolean", "int".
Can anyone help me out? I believe it tends to be simple but I am not an expert, yet. Thanks in advance.
In fact I have a function A who receives a list of parameters, but then it's function B who will also use these parameters but B's parameters list is vide, so I hope to store them as a class parameter and reused by function B. So here is what I did:
Class Person() {
Map<String, T> infoPaire; // if I use Object to replace T
Function A: receiver(boolean b, int i, String1 st1, String2 st2) {
infoPaire.put("b", b);
infoPaire.put("i", i);
infoPaire.put("st1", st1);
infoPaire.put("st2", st2);
}
Function B: user() {
boolean b = infoPaire.get("b"); // I need to add (boolean) to cast and I dont want it, it's ugly
int i = infoPaire.get("i");
String st1 = infoPaire.get("st1");
String st2 = infoPaire.get("st2");
}