开发者

Usage of eclipse warning "field declaration hides another field or variable"?

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;
   }
}

I've seen solutions where the field is renamed, i.e "fCap开发者_Go百科tion", but that would cause the automatic getters/setters that can be genereated to have odd names (getfCaption()). Not unreadable, but ugly...

Edit: 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.


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.

Usage of eclipse warning "field declaration hides another field or variable"?


I'd say that you just disable this warning - it seems no use in your convention. And no wonder it is ignored by default.


I keep these set to "Error". If a class and its parent both have a field of the same name I don't want to lose any of my time trying to figure out why I seem to be assigning a value to the field yet it never seems to change!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜