How can I generalize a Hashmap type in Java? -
How can I generalize a Hashmap type in Java? -
i generalize result homecoming within function of application. homecoming hashmap result , parse ui, showing user.
i want extend values application returns. quick example:
public class model implements runnable { private hashmap<string, integer> result; public hashmap<string, integer> returntheanswertoeverything() { hashmap<string, integer> result = new hashmap<string, integer>(result.putall(answer(universe)); // returns (universe,42) homecoming result; } }
with result returning hashmap along results. in seperate function or gui can output user. if want not homecoming integer, additional stuff, how best?
if wanted homecoming universe third(fourth ...) answer? how maintain extendable?
if want homecoming additional info besides integer
, create wrapper class store data, , set map
.
public youradditionalinfoclass { // if want getter/setters or public visibility public integer yourintegervalue; // replace object additional class want public object youradditionalinfo; } public hashmap<string, youradditionalinfoclass > returntheanswertoeverything()
java
Comments
Post a Comment