Possible Duplicate:
Java - when to use 'this' keyword
Is it generally good convention to references class attributes with 'this.' even if it would reference the attribute by default anyway? Or should I only use it when absolutely necessary?
It would make things clearer to the programmer, and to avoid any confusing errors if the programmer added any new variables with the same name.
Some people have a convention for private member variables to prepend or append an underscore. In those cases, it's pretty clear that the this
is implied.
If you don't have a naming convention for private members, then the this
is a good way to indicate that the variable you are reading/writing is a member variable.
I prefer not to have any variables with different scopes (parameters, members, locals) ever sharing the same name. I avoid that with a naming convention for members.