Map<String, String> is a subtype of Map<?, ?> , But since generics are not invariant, this does not mean that List<Map<String, String>> is a subtype of List<Map<?, ?>> .
If you are sure that all keys and values ββare String instances, you can do this
List<Map<String, String>> circle = (List<Map<String, String>>) (Object) FileManager.area.getMapList("circles");
However, I would not recommend it, because if any of the keys or values ββis not String , you can get a ClassCastException later, so that you throw away the guarantee that generic tools generate.
An alternative would be to create a new ArrayList<Map<String, String>>() and iterate over List<Map<?, ?>> , and then use instanceof to check all the keys and values ββin each Map<?, ?> String . Only if the instanceof check is successful do you need to add an entry.
source share