#cec726
提示:String concatenation as argument to 'StringBuilder.append()'
详细提示
String concatenation as argument to 'StringBuilder.append()' call less... (Ctrl+F1)
Inspection info: Reports String concatenation used as the argument to StringBuffer.append(), StringBuilder.append() or Appendable.append(). Such calls may profitably be turned into chained append calls on the existing StringBuffer/Builder/Appendable, saving the cost of an extra StringBuffer/Builder allocation.
This inspection ignores compile time evaluated String concatenations, which when converted to chained append calls would only worsen performance.
解释
append方法就是为了解决String += String的效率问题的,而上面代码在append方法里使用了字符串连接,可能降低性能。解决提示:不要在append方法里写字符串连接代码。
C-style array declaration of local variable 'arr' less...
详细提示
C-style array declaration of local variable 'arr' less... (Ctrl+F1)
Inspection info: Reports array declarations made using C-style syntax, with the array indicator brackets positioned after the variable name or after the method parameter list. For example:
public String process(String value[])[] {
return value;
}
Most code styles prefer Java-style array declarations, with the array indicator brackets attached to the type name.
解释
数组对象,把中括号放在变量后面是C语言的风格,而Java习惯放在变量类型后面
'for' loop replaceable with 'foreach' less...
详细提示
'for' loop replaceable with 'foreach' less... (Ctrl+F1)
Inspection info: Reports for loops which iterate over collections or arrays, and can be replaced with the foreach iteration syntax, available in Java 5 and newer.
解释
循环遍历集合或数组,可以替换为foreach迭代语法
Local variable 's' is redundant less...
详细提示
Local variable 's' is redundant less... (Ctrl+F1)
Inspection info: Reports unnecessary local variables, which add nothing to the comprehensibility of a method. Variables caught include local variables which are immediately returned, local variables that are immediately assigned to another variable and then not used, and local variables which always have the same value as another local variable or parameter.
解释
定义的变量名称是冗余的
Field injection is not recommended less...
详细提示
Field injection is not recommended less... (Ctrl+F1)
Inspection info: Spring Team recommends: "Always use constructor based dependency injection in your beans. Always use assertions for mandatory dependencies".
解释
Spring团队建议:“始终在bean中使用基于构造函数的依赖注入
Found duplicate code
鼠标放在重复代码块,Alt+Enter
查看其它重复代码,可以做比较
Call to 'toArray()' with pre-sized array argument 'new String[prdCodeList.size()]'
详细提示
Call to 'toArray()' with pre-sized array argument 'new String[prdCodeList.size()]' less... (Ctrl+F1)
Inspection info: There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]).
In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty array version the same and sometimes even better, compared to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray call which may result in extra nulls at the end of the array, if the collection was concurrently shrunk during the operation.
This inspection allows to follow the uniform style: either using an empty array (which is recommended in modern Java) or using a pre-sized array (which might be faster in older Java versions or non-HotSpot based JVMs).
解释
有两种样式将集合转换成数组:
1. c.toArray(new String[c.size()])
2. c.toArray(new String[0])
在旧的Java版本中,建议使用预大小的数组,因为创建适当大小的数组所必需的反射调用非常慢。
JDK6开始,与预设置大小的版本相比,空数组版本的性能相同,有时甚至更好。现在推荐使用空数组版本
'if' statement can be simplified
详细提示
'if' statement can be simplified less... (Ctrl+F1)
Inspection info: Reports if statements which can be simplified to single assignment, return or assert statements.
For example:
if (foo()) {
return true;
} else {
return false;
}
can be simplified to
return foo();
解释
因为你if语句里的判断结果就是Boolean类型的,所以你不必脱了裤子放屁。【JDK源码和Spring源码,这种代码随处可见】