I'm trying to call a Java method with a HashMap as the parameter. The HashMap takes a String as it's key, and an Object as it's value. When I call that method, I send up a HashMap with a String as its key and an object that I created, Building, as the value. Since an object by default extends the Object class, is this not valid? Similar to this?:
List<Integer> a = new ArrayList<>();
Here is the code that I am running:
private void populateMap(HashMap<String, Object> map){
/*Code is in here*/
}
public static void main(String[] args){
HashMap<String, Building> buildings = new HashMap<>();
populateMap(buildings);
}
But it's resulting in an error, saying that I can't send the buildings HashMap, as the parameter is expecting an Object as the value. How is this different than the List/ArrayList example I included above, and is there any way that I can make this work? I want to be able to call this method with multiple HashMaps, each of which has it's own unique object as the value, but I wanted to avoid creating multiple identical methods with the only difference being the method header.