Is there a reason why Eclipse reports type safety warning in the following declaration?
Map<String,List<Map<String, ParseNode>>> mapX = new HashMap();
I understand that all mapX usages would be strongly typed but what can possibly be achieved by java generics insisting on providing HashMap paramaterized type (other than adding noise to the code)?
Your declaration is invalid.
Using Generics (Parameterized Types)
Using Java 5 to 6, you should write:
Starting with Java 7, you can simplify this with:
Your syntax means something different and uses a raw type:
Update:
To answer your question, this has implications (as mentioned by the Java Tutorial):
Basically meaning that the parameterization of your type here doesn’t have much meaning.
The code following this declaration will be compiled with the assumptation that it contains values with the types as declared. However at runtime, you declared a type of a raw type, and you could very well have assigned a map containing different values to this entry.
What you wrote would be the equivalent of writing something like:
Which would compile fine, and blow up in your face at runtime when you try to access one of
m‘s values as aList<Map<String, ParseNode>>.Reasons
The reason for this is that Generics where introduced while conserving complete backwards compatibility at the source level, hence some of their limitation, like:
<>),Further Reading