使用eclipse warning“字段声明隐藏另一个字段或变量”? [英] Usage of eclipse warning "field declaration hides another field or variable"?
问题描述
Eclipse有一个名为
的Java编译器设置,字段声明隐藏了另一个字段或变量,可以设置为warning / error。
Eclipse has a java compiler setting called "field declaration hides another field or variable" that can be set to warning/error.
这个警告在你看来?
这是一个很好的标准方法来处理这个问题?
What is a good standard way to handle this problem?
p>
Code example of where this happens:
public class Test {
private String caption = null;
public Test(String caption) { // here
this.caption = caption;
}
}
我看过解决方案中的字段重命名,即fCaption,但这将导致可以生成的自动getter / setter具有奇怪的名称( getfCaption()
)。
不可读,但是丑陋...
I've seen solutions where the field is renamed, i.e "fCaption", but that would cause the automatic getters/setters that can be genereated to have odd names (getfCaption()
).
Not unreadable, but ugly...
编辑:哦,有可能重命名方法签名 Test caption _)
或类似的东西,但最终会在javadoc看起来很奇怪。
Oh yea, there is the possibility to rename the method signature Test(String caption_)
or something similar, but that would end up in the javadoc looking weird.
推荐答案
在我看来这是一个非常有用的选项,应该启用显示编译器警告。有一个选项(在我的版本至少Eclipse 3.5.2,Java EE功能1.2.2),以进一步在构造函数和getters / setter中启用/禁用它,以防止误报。
This is a very useful option in my opinion and should be enabled to show a compiler warning. There is an option (in my version at least Eclipse 3.5.2, Java EE feature 1.2.2) to further enable/disable it within constructors and getters/setters to prevent false positives.
这篇关于使用eclipse warning“字段声明隐藏另一个字段或变量”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!