java日常开发中,经常会碰到开发工具idea、Eclipse等在一些代码中报黄线,这对于很多具有强迫症的同学来说,也是一件很头疼的事,尤其是编码不注意规范的同学来说。
下面我就列举一些常见的黄线预警及其解决办法:
1、Reports local variable of wrapper type though all usages allowed to be primitive and count of unnecessary boxing/unboxing operations reduces
例:
解决方案:将黄线部分的包装类型Integer改成对应基本数据类型,即int
2、Unchecked assignment: ‘java.util.LinkedHashMap‘ to ‘java.util.Map
例子:
解决方案:添加泛型尖括号
new LinkedHashMap<>();
3、‘while‘ loop replaceable with ‘foreach‘
例:
解决方案:
Iterator var2 = list.iterator();
for (;var2.hasNext();){
Object tem = var2.next();
maps.add(beanToMap(tem));
}
或者
Iterator var2;
for (var2 = list.iterator(); var2.hasNext();) {
Object tem = var2.next();
maps.add(beanToMap(tem));
}
3、‘for‘ loop replaceable with ‘foreach‘
例:
解决方案:
for (String attr : attrs) {
//xxx
}
3、持续更新中...
原文:https://www.cnblogs.com/tobiasy/p/11597098.html