I am basically trying to do a check of a Map
in Java. My code is as follows.
private boolean isValid(Map<?,?> map) {
return (null != map && map.size() > 0);
}
Why can't I use this method as follows?
Map<String, String> m = new HashMap<>();
isValid(m);
In Eclipse, I get the following error message:
The method isValid(Map<?,?>) in the type MyClazz is not applicable for the arguments (Map<String,String>)
As I am writing this question, I tried the following and it "works".
isValid( (Map<?,?>) m);
Why is this? Thumbing through the SO posts, I got a "similar" problem stating the problem of wildcard capture. But it doesn't seem like that's the problem here (without casting).