正确案例:
1.多条件下可以通过case 7: case 3: 执行条件或|,简而言之就是
if (type ==7 || type == 3){
…
}
case 0:
final String v1 = row.get(field).toString();
row.put(field, v1);
break;
case 1:
final Float v2 = Float.parseFloat(row.get(field).toString());
row.put(field, v2);
break;
case 7:
case 3:
final Long v3 = Long.parseLong(row.get(field).toString());
row.put(field, v3);
break;
case 11:
case 10:
case 6:
case 2:
final Integer v4 = Integer.parseInt(row.get(field).toString());
row.put(field, v4);
break;
2.错误案例: switch case 不支持 | 的方式执行!!!闭坑!!!,最终执行判定的时候导致所有都执行不成功!也没有报错提醒!!
case 2|7:
final Integer v4 = Integer.parseInt(row.get(field).toString());
row.put(field, v4);
break;
文章分析了在Java中使用case分支处理不同类型数据时的正确用法(如Integer.parseInt),以及错误案例中switch不支持逻辑或运算导致的问题,强调了条件判断的严谨性与错误处理的重要性。
855

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



