I am wondering why the second map declaration (using the diamond operator) does not compile when the first one does. Compilation error:
error: cannot
You don't have a static initializer here (the keyword static is missing altogether).
Basically you create a new anonymous subclass of HashMap and define the instance intializer block here. Btw, this only works since HashMap is not final.
Since you'll get an anonymous subclass of HashMap the diamond operator doesn't work here, since the subclass would then be compiled as if you wrote ... extends HashMap and this clearly isn't compatible to Map.