eclipse警告“字段声明隐藏另一个字段或变量"的用法? [英] Usage of eclipse warning "field declaration hides another field or variable"?
问题描述
Eclipse 有一个名为的 java 编译器设置字段声明隐藏了另一个字段或变量",可以设置为警告/错误.
Eclipse has a java compiler setting called "field declaration hides another field or variable" that can be set to warning/error.
您认为此警告有多重要?
How important is this warning in your opinion?
处理这个问题的好的标准方法是什么?
What is a good standard way to handle this problem?
发生这种情况的代码示例:
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(String 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)可以在构造函数和 getter/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警告“字段声明隐藏另一个字段或变量"的用法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!