Cast a List type object without iteration
There are three choices as follows:
List<String> list = Arrays.asList("1","2"); List<Object> objectList = (List) list; List<Object> objectList2 = (List<Object>)(List<?>) list; List<Object> objectList3 = new ArrayList<Object>(list);
But the choice 1 and 2 seem to be dangerous because the exception will be thrown when the item of the list is fetched if the list is not a List<Object>
.