findbugs检测提示详解(3)

2019-01-07 14:06

22、内部类没有引用外部类的属性/方法的时候,应该作为静态内部类

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.

23、包装类的比较应该使用 eueqls,要比较值类型,需要强制类型转换后再使用

This method compares two reference values using the == or != operator, where the correct way to compare instances of this type is generally with the equals() method. It is possible to create distinct instances that are equal but do not compare as == since they are different objects. Examples of classes which should generally not be compared by reference are java.lang.Integer, java.lang.Float, etc.

例 getTypeCodeID() 和getSpecCodeID() 方法均返回Integer

if (configReaderInfo.getTypeCodeID() == realReaderInfo.getTypeCodeID()

&& configReaderInfo.getSpecCodeID() == realReaderInfo .getSpecCodeID()) { return true; }

public class NumberTest {

public static void main(String[] args) { Integer a = new Integer(1); Integer b = new Integer(1);

System.out.println(a == b); //结果是false } }

24、Write to static field from instance method

不要通过实例方法给静态变量赋值。


findbugs检测提示详解(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:自动化专业概论大作业及评分标准

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: