What is wrong with this instantiation :
Map<String, String, HashMap<String,String>> map = new HashMap<String, String, HashMap<String,String>>();
A Map<K,V>
is a mapping from keys of type K
to values of type V
. There are only 2 type parameters to a map.
You attempted to define a map with 3 type parameters; this is not possible, and has nothing to do with the fact that you're putting a Map
inside a Map
.
A Map<K1,Map<K2,V2>>
works just fine.
A Map<X,Y,Z>
does not.
It's possible that you need something like Map< Pair<L,R>, Map<K,V> >
. Java does not have generic Pair<L,R>
type, but see related questions below for solutions.
On pairs/tuples:
Pair<L,R>
in Java? Pair<String, String>
stored in HashMap
not retrieving key->value properly On nested maps:
Maps only have 2 type parameters, you have 3 (in your "outer" Map).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With