What is wrong with this statement?
private final HashMap<String, SortedMap<Long, Long>> abc;
abc = new HashMap<String, TreeMap<Long, Long>>;
It shows the error that SortedMap cannot be converted to TreeMap like this? How do I make this possible?
If you really want to be able to assign it this way, then can you use a wildcard with bound
? extends SortedMap. eg:That said, you don't have to specify the nested map type when you create the new outer hashmap instance.. just keep it as a
SortedMap. Later when you insert a value it can be newTreeMapinstances because they implementSortedMap. egAfter shortening this code for type inference, the assignment lines could look like bellow: