Lists and unchecked conversions

74 views Asked by At

In trying to fix a warning about "Type safety: The expression of type List needs unchecked conversion to conform to List". Basically taking a List of Objects and casting it to a List of InventoryPDFAdapter.

This was the code which was throwing the warning

//List<InventoryPDFAdapter> invList = stratificationMap.get(stratification);

This is my solution

List untypedList = stratificationMap.get(stratification);
List<InventoryPDFAdapter> invList = new ArrayList<InventoryPDFAdapter>();
for(Object o : untypedList) {
    invList.add((InventoryPDFAdapter)o);
}

Is there a more elegant way to do this while still avoiding the warning?

0

There are 0 answers