Using eclipse warning "hides another field or variable"?

Eclipse has a java compiler option called "declaring a field hides another field or variable" that can be set to a warning / error.

How important is this warning in your opinion?

What is a good standard way to solve this problem?

Sample code where this happens:

public class Test {
   private String caption = null;

   public Test(String caption) { // here
     this.caption = caption;
   }
}

I saw solutions in which the field was renamed, i.e. "fCaption", but this can cause automatic getters / setters to be scattered with odd names ( getfCaption()). Not readable, but ugly ...

Edit: Oh yes, it is possible to rename a method signature Test(String caption_)or something similar, but that will turn out to be in javadoc looking weird.

+5
3

, , , . ( , , Eclipse 3.5.2, Java EE 1.2.2), / /, .

eclipse compiler settings

+9

, - . , .

+1

I keep this set in "Error". If the class and its parent have the same name, I do not want to lose any time trying to understand why I seem to assign a value to the field, but it never changes!

0
source

All Articles