The following code compiles but if I uncomment the commented line, it does not and I am confused why. HashMap does extend AbstractMap and the first line where map is declared compiles fine.
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
public class Test {
public static void main(String args[]) {
Map<String, ? extends AbstractMap<String, String>> map = new HashMap<String, HashMap<String, String>>();
//map.put("one", new HashMap<String, String>());
}
}
And, I know the "right way" is this:
import java.util.HashMap;
import java.util.Map;
public class Test {
public static void main(String args[]) {
Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
map.put("one", new HashMap<String, String>());
}
}