项目代码优化(三)

来源:互联网 发布:json解析框架 编辑:程序博客网 时间:2024/05/22 03:21

无效对象

  • 场景
JSONObject total = new JSONObject(); 
  • 解释
  • 英文
Dodgy - Dead store to local variableThis instruction assigns a value to a local variable, but the value is not read or used in any subsequent instruction. Often, this indicates an error, because the value computed is never used.Note that Sun's javac compiler often generates dead stores for final local variables. Because FindBugs is a bytecode-based tool, there is no easy way to eliminate these false positives.This rule is deprecated, use S1481 instead.
  • 中文
1.此指令将值赋给局部变量,但该值不再任何后续指令中读取或使用,其实就是创建了一个无用对象在内存当中。2.对于此类代码,虽然不会影响系统的正常运行,但是如果此类代码过多,会暂用一些内存,建议功能项目中,应当移除此类代码。

字符串转换成数字

  • 场景
int taskId = Integer.valueOf(request.getParameter("taskId"));
  • 解释
  • 英文
Boxing/unboxing to parse a primitiveA boxed primitive is created from a String, just to extract the unboxed primitive value. It is more efficient to just call the static parseXXX method.This rule is deprecated, use S2130 instead.findbugs:DM_BOXED_PRIMITIVE_FOR_PARSING Efficiency > Memory use
  • 中文
1.使用Integer.valueOf(0)专门用于处理对象类型的数字,虽然也可以用来处理字符串转换成数字。2.建议使用Integer.parseInt("0");此方法专门用于将字符串转换成数字。
0 0
原创粉丝点击