I should know this, but I can't understand this for some reason.
Why can I not cast a List of Objects List<Object>
to a List of Maps List<Map<String, Object>>
? Every object in the list is an object of type Map<String, Object>
, so why is the casting not possible?
What I can do is create a new ArrayList<Map<String, Object>>();
and iterate over the list and add each item with a cast.
List<Object> dataList;
..
//Why doesn't this work?
List<Map<String, Object>> rxData = (List<Map<String, Object>>)dataList;
//This works, but is there a better way?
rxData = new ArrayList<Map<String, Object>>();
for (Object data : dataList) {
rxData.add((Map<String, Object>)data);
}