Java setters and "this"
java
Solution
It's a matter of style. The argument in favor of
public void setX(int x) { this.x = x; }
is that you don't need to think of a new and meaningful name for the input argument, since you already have one.
Pick a style and use it consistently.
Problem
I have noticed in alot of people do in Java setters: 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 the first would be better? Isn't 1) easier to make an error with. On a few occassions I have tracked bugs in code down to people doing: ``` x = x; ``` by mistake, maybe because they were typing to fast and just wanted to get the getters and setters out of the way.