I’m trying to cast a Map like this :
Map<Integer, Map<String, String>> map =
(HashMap<Integer, Map<String, String>>) pMap;
pMap is typed :
Map<Object, Map<Object, Object>> pMap
Unfortunately it doesn’t work and I’m curious to know why, and also if it’s possible to avoid the problem.
This is because even though
Integeris a subtype ofObject,Map<Integer, Integer>is not a subtype ofMap<Object, Object>.You simply cannot cast it that way.
This is explained further in the Java Tutorials.