I am trying to create a map of maps using the ConcurrentSkipListMap
. If I create a simple map example it seems to be fine:
Map<Integer, Integer> mmap2 = new ConcurrentSkipListMap<Integer, Integer>();
Once I try to create a map of maps, I get a Incompatible types
error:
Map<Integer, Map<Integer, Integer>> mmap =
new ConcurrentSkipListMap<Integer, ConcurrentSkipListMap<Integer, Integer>>();
If I switch the definition to include a ConcurrentSkipListMap
, its compiles with no problems:
Map<Integer, ConcurrentSkipListMap<Integer, Integer>> mmap =
new ConcurrentSkipListMap<Integer, ConcurrentSkipListMap<Integer, Integer>>();
Why cant I define the map of map's using the Map
interface?
I can answer the question with an example.
In this case, do you expect the put line to be allowed? If it is not allowed then it breaks the definition of mmap. If it is allowed then it breaks the right hand side.
You've produced a line a code that whether it works or not gives you a contradiction. Therefore we don't allow such definitions of mmap.