I have a method that expects a generic map in parameter :
public void someMethod(Map<String,?> mapParameter){ ... } My implementation that calls this method, have multiple possible values to the "?" generic param. For example, sometimes the value in "?" will be Integer, others it will be String, Boolean.
Exists some way to declare a fully generic HashMap that can accept my values, and passed to the "someMethod" method ?
I tried to extract the values to classes "IntegerValueDTO", receiving the value in String value and converting to the especific type. All this "valueDTO" classes created, i put to extend from "defaultValue". With this, i implemented this map :
Map<String, ? extends DefaultValue> map = new HashMap<String, ? extends DefaultValue>(); But, the method someMethod is not from my application, it is from a framework, then i dont have the control to chance the implementation. And declaring my map that way, he will generate a map of "Map<String, some instance of DefaultValue>", and the framework crashes.
Any help will be welcome.
Map<String, ?>, or aMap<String, Foo>, or aMap<String, ? extends Foo>. Is the problem writing something that compiles, or something that runs?