I need to iterate over the entry set of a map from which I do not know its parameterized types.
When iterating over such entryset, why this does not compile ?
public void myMethod(Map anyMap) {
for(Entry entry : anyMap.entrySet()) {
...
}
}
but this compile:
public void myMethod(Map anyMap) {
Set<Entry> entries = anyMap.entrySet();
for(Entry entry : entries) {
...
}
}
and this also compiles (I cannot use this one since I do not know the types of the map):
public void myMethod(Map<String, String> stringMap) {
for(Entry<String,String> entry : stringMap.entrySet()) {
...
}
}