Your declaration is invalid.
Using Generics (Parameterized Types)
Using Java 5 to 6, you should write:
Map<String, List<Map<String, ParseNode>>> m =
new HashMap<String, List<Map<String, ParseNode>>>();
Starting with Java 7, you can simplify this with:
Map<String, List<Map<String, ParseNode>>> m = new HashMap<>();
Your syntax means something different and uses a raw type:
Map<String, List<Map<String, ParseNode>>> m = new HashMap();
Update:
To answer your question, this has implications (as mentioned by the Java Tutorial):
Note that to take advantage of automatic type inference during generic
class instantiation, you must specify the diamond. [In your case] the
compiler generates an unchecked conversion warning
because the HashMap() constructor refers to the HashMap raw type, not
the [parameterized Map] type.
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:
Map rawMap = new HashMap();
rawMap.add("string", "not list!");
Map<String, List<Map<String, ParseNode>>> m = rawMap; // uh oh!!
Which would compile fine, and blow up in your face at runtime when you try to access one of m
's values as a List<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:
- the impossibility to have a short-hand form without at least some indicator for generics support (here, the so-called diamond operator
<>
),
- the impossibility to inspect generic-types at runtime, because they had to be implemented with Type Erasure.
Further Reading