Is "this" shadowing a good idea?
java, shadowing
Solution
I actually prefer the guideline "Shadowing is only allowed in constructors and setters". Everything else is not allowed. Saves you the trouble of naming constructor arguments `aValue` and `aTest` just to avoid shadowing.
If you're using eclipse, its warnings settings can be set exactly to that option BTW.
Problem
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?