The case of shadowing class variables is common in in Java. Eclipse will happily generate this code:
public class TestClass {
private int value;
private String test;
public TestClass(int value, String test) {
super();
this.value = value;
this.test = test;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}
Is variable shadowing ever ok?
I am considering the implementation of a coding rule saying that "shadowing will not be allowed." In the simple case above it is clear enough what is going on. Add in a little more code that does something and you run the risk of missing "this" and introducing a bug.
What is the general consensus? Ban shadowing, allow it sometimes, or let it roll?