I recently saw the following on this site:
for (HashMap.Entry<Object,Object> e : new TreeMap<>().entrySet()) System.out.println(e);
To my surprise, this compiles and works just fine. I also tried adding entries to the card so that there really was something to knock down and not do it, this worked fine too. How to write TreeMap in HashMap.Entry ? These two are not even in the same hierarchy branch.
Update
Although this question is now resolved, I am including the following for hobby only: mdash: the following does not compile:
for (TreeMap.Entry<Object,Object> e : new HashMap<>().entrySet()) System.out.println(e);
It happens that TreeMap defines TreeMap.Entry , which hides Map.Entry .
source share