Why doesn’t that work in java, but this does
Map<String, Map<String, Boolean>> myMap = new HashMap<String,Map<String,Boolean>>();
Just to clarify the below alteration of the nested HashMap shows a compiler error, whereas the above does not not; with a Map (not hashmap)
Map<String, Map<String, Boolean>> myMap = new HashMap<String,HashMap<String,Boolean>>();
This is because generics in Java are invariant, i.e. even if class B is an A, a
Collection<B>is not aCollection<A>.And this is for a good reason. If your example were legal, this would be possible: