I wrote the following method
validate(Map map)
And I want to call it with
dogMap = new HashMap
You have to declare the method with type boundaries:
validate(Map<String,? extends IAnimal> map)
See http://docs.oracle.com/javase/tutorial/extra/generics/wildcards.html for further explanations of Java (Bounded) Wildcards.
You can change the signature of validate to :
validate(Map<String,? extends IAnimal> map)
This will allow you to pass any map with a String key and a value that extends or implements IAnimal.
You have two options:
validate to YourReturnType validate(Map<? extends String, ? extends IAnimal> map) (assuming you do not want to add elements to it).Map<String, IAnimal> from the dogMap you want to pass: new HashMap<String, IAnimal>(dogMap) and pass that object to validate.