I have a question about the this operator in Java. In the case where a programmer would write a code like this:
private int counter;
public Incrementor(int counter){
this.counter = counter;
}
Would it be better to avoid shadowing effect and go with this:
private int counter;
public Incrementor(int startValue){
counter = startValue;
}
Wouldn’t the this operator make the this operator obsolete in future programming execrises?
The “this” keyword is very useful. Your example is clear, but imagine the situation in which you have to pass a self reference to another method of an external object.