I use this
when I think it will communicate more clearly without cramping my style. In particular, set methods are a great place where I like to have the clear match between the data member and the method parameter:
public void setImportantValue(double importantValue) {
this.importantValue = importantValue;
}
With colorized IDEs, this is a little bit redundant but if it helps me work better with my fellow humans, it's a win.
Edit: Thorbjørn reminded me of an excellent point:
Using "this" allow you to have the
same name for the parameter as for the
field, which clearly shows intent.
Also the parameter name ends up in the
signature which is what you see in the
IDE - having correspondence between
setter name and argument removes all
doubt.
I was reminded that the user of your code usually only sees your external API. For example, if we want to make it clear to the user (either via javadoc, code completion or IDE mouse-overs) that a method is going to adjust the Euler angles of a simulated airplane, we might use a method such as:
public void setOrientation(double roll, double pitch, double yaw) {
this.roll = roll;
this.pitch = pitch;
this.yaw = yaw;
}
It is clear from the externally-exposed interface and the parameter names what I'm trying to accomplish. I could even make things a little more clear with @param javadoc tags.
The fact that I need to do a little more typing of "this.roll", etc., is a very small price for me to pay to make the both API-user's life easier and the API-maintainer's task more clear. This is especially true since I only pay the price once.