Java: polymorphism applied to Map generic types -


i want have function (for example) outputs values of 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 following doesn't seem work:

public void output(map<string, object> map, string key) {     system.out.println(map.get(key).tostring());  } 

are not both string , integer of type object?

map<string, string> not extends map<string, object>, list<string> not extend list<object>. can set value type ? wildcard:

public void output(map<string, ?> map, string key) {  // map value of type     // can call tostring because value object     system.out.println(map.get(key).tostring()); } 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -