- A 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.
修改建议:使用Long.ParseLong,避免自动装箱再拆箱
问题原因:
Long.ParseLong(String)方法,将 string 参数解析为有符号十进制 ,返回一个long的基本类型值
Long.ValueOf(String) ,方法得到的值非常相似。只是最后被转换为一个Long的包装类 - This class is an inner class, but does not use its embedded reference to the object which created it. This reference makes the instances of the class larger, and may keep the reference to the creator object alive longer than necessary. If possible, the class should be made static.
修改建议:若成员类中未访问外围类的非静态成员,为避免额外的空间和时间开销,建议改用静态成员类。
问题原因:
非静态成员类和静态成员类的区别在于,非静态成员类是对象的,静态成员类是类的。非静态成员类可以访问外围类的任何成员,但前提是必须存在外围类对象。JAVA需要额外维护非静态成员类和外围类对象的关系。 - This code generates a hashcode and then computes the absolute value of that hashcode. If the hashcode is Integer.MIN_VALUE, then the result will be negative as well (since Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE).
One out of 2^32 strings have a hashCode of Integer.MIN_VALUE, including “polygenelubricants” “GydZG_” and “”DESIGNING WORKHOUSES”.
修改建议:在使用之前判断一下是否是为Integer.MIN_VALUE
问题原因:
此代码产生哈希码,然后计算该哈希码的绝对值。如果哈希码是Integer.MIN_VALUE的,那么结果将是负的(因为Math.abs(Integer.MIN_VALUE)==Integer.MIN_VALUE)。 - A boxed value is unboxed and then immediately reboxed.
修改建议:三元运算符两个分支的返回类型保持一致。
问题原因:
装箱的值被拆箱,然后立刻重新装箱 This class defines a field with the same name as a visible instanc
findbugs规则整理及解决办法
最新推荐文章于 2024-05-13 21:45:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)