java - Is this code sample really returning the right parameterized types? -
I have read articles about Java archives, and my note of the following snippet is:
< Code> Map & lt; String, map & lt; Long, list & lt; String & gt; & Gt; & Gt; Map = maps.newHashMap ();
The thing is, I do not know how it is possible that newHashMap
method is a map & lt; String, map & lt; Long, list & lt; String & gt; & Gt; & Gt;
. How did they write this code? When was this possible? I lived under the assumption that you need to explicitly declare generic parameters in the constructor call.
You can declare generic parameters on a common column, not just a whole class. If you look at the source of that method:
public stable Hashmap & lt; K, V> NewHashMap () {New Hashmap Back < K, V> (); }
You will see that it declares two generic parameters, K and V and declares the result as a map. The compiler is smart enough to remove K and V from LHS expression. In your case, K is string
and V is map & lt; Long, list & lt; String & gt; & Gt;
Comments
Post a Comment