I want to have a function which (for example) outputs all the values of a Map in both cases:
Map<String, String> map1 = new HashMap<String, String>();
Map<String, Integer> map2 = new HashMap<String, Integer>();
output(map1, "1234");
output(map2, "4321");
And the following doesn't seem to work:
public void output(Map<String, Object> map, String key) {
System.out.println(map.get(key).toString());
}
Are not both String
and Integer
of type Object
?