在用Eclipse开发java程序时,使用Java数据类型List时,Eclipse总是提示警告,虽然不报错,程序也能正常运行,但是看着挺不爽的(好吧,我承认自己有强迫症)。警告信息如下:
Type safety: Unchecked cast from List to List<AgentCharge>
表明Object转化为ArrayList并不是安全的,以下是收集的取消警告的方法(危险的解除依赖于程序员确保转化的目标类型和原类型一致):
第一:方法上添加@SuppressWarnings("unchecked")
第二:myeclipse的Window->Preferences->Java->Compiler->Errors/Warning->Generic types中Unchecked generic type operation设置为Ignore。
第三:myeclipse的Window->Preferences->Java->Compiler将Compiler compliance level 设置为小于1.5。
示例代码:
public List<AgentCharge> selAgentChargeById(AgentCharge agentCharge) {
log.debug("selAgentChargeById开始执行");
@SuppressWarnings("unchecked")
List<AgentCharge> list = (List<AgentCharge>)getSqlMapClientTemplate().queryForList("AgentCharge.selAgentChargeById", agentCharge);
return list;
}
本文提供了解决在Eclipse环境下开发Java程序时遇到的关于List类型的警告信息方法,包括使用@ SuppressWarnings注解、修改MyEclipse配置及降低编译器合规级别等解决方案。
619

被折叠的 条评论
为什么被折叠?



