在尝试修复有关“类型安全:类型列表的表达式需要未经检查的转换以符合列表”的警告时。基本上获取对象列表并将其转换为 InventoryPDFAdapter 列表。
这是引发警告的代码
//List<InventoryPDFAdapter> invList = stratificationMap.get(stratification);
这是我的解决方案
List untypedList = stratificationMap.get(stratification);
List<InventoryPDFAdapter> invList = new ArrayList<InventoryPDFAdapter>();
for(Object o : untypedList) {
invList.add((InventoryPDFAdapter)o);
}
有没有更优雅的方法来做到这一点,同时仍然避免警告?