Following code fails compilation with error following error message :
Type mismatch: cannot convert from element type Test1.Entry to Map.Entry
My question is can't we ever use class with name Entry
in our project while using hash map
? And why this error is there though i did not import any Entry
class here.
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
public class Test1 {
public static class Entry<T> {
public String m() {
return "A";
}
}
public static void main(String[] args) {
final Set<Entry> a = new HashSet<>();
new HashMap<String, Entry>() {
{
for (final Entry entry : a) {
put(entry.m(), entry);
}
}
};
}
}
Is there any way I can keep this class name and code compiles successfully.