【发布时间】:2019-02-19 00:05:34
【问题描述】:
我目前正在处理另一个人项目的一些 Findbugs 问题。
这是我正在处理的问题:
正确性 - 类定义了掩盖超类字段的字段
该类定义了一个与超类中的可见实例字段同名的字段。这很令人困惑,并且如果方法在需要另一个字段时更新或访问其中一个字段,则可能表示错误。
有超类OutputInterface 和扩展OutputInterface 的子类CoreOutputInterface。它们都定义了变量className。
CoreOutputInterface 也有一些子类。
要解决此问题,我只需从子类 (CoreOutputInterface) 中删除 className,因为它已在超类中定义。
变量永远不会被super.className 或this.className 读取或设置,只有className,所以在我看来它不应该导致任何问题。
此外,整个项目中从未引用超类中的变量(我使用 Eclipse 引用函数检查了它)。
谁能确认这在任何情况下都不会导致问题?
提前感谢您的帮助。
输出接口:
public abstract class OutputInterface {
protected String className = null;
...
}
核心输出接口:
public abstract class CoreOutputInterface extends OutputInterface {
protected String className = null;
...
public void getClassName() {
return className;
}
public void setClassName(String newName) {
className = newName;
}
...
}
【问题讨论】:
标签: java variables subclass superclass findbugs