I noticed that many people do in Java installations:
1)
public void setX(int x) {
this.x = x;
}
Personally, I don't like this, and I think it should be something like:
2)
public void setX(int newX) {
x = newX;
}
Are there any reasons for the former to be better?
Not 1) itβs easier to make a mistake. On several occasions, I tracked code errors that people make:
x = x;
mistakenly, maybe because they typed quickly and just wanted to remove getters and setters.
source
share