This is a Java question.
What is the fastest way to convert a List<?> to a List<ObjectType>? I am aware that this is possible through iteration please exclude that option.
Example by iteration,
final List<ObjectType> targetList = new ArrayList<ObjectType>();
// API returns List<?> so I have no choice.
List<?> resultList = resultSet.getResults();
// This is slow. Average list size is 500,000 elements.
while (resultList != null && !resultList.isEmpty()) {
for (final Object object : resultList) {
final ObjectType objectType = (ObjectType) object;
targetList.add(objectType);
}
resultSet = someService.getNext(resultSet);
resultList = resultSet.getList();
}
Thanks.
It’s a bit scary but depending on context you could possibly get away with just casting: