Alex Rivera | Logout

When should I use "this" in a class?

Asked 2010-03-09T17:57:04.147
378

I know that this refers to a current object. But I do not know when I really need to use it. For example, will be there any difference if I use x instead of this.x in some of the methods? May be x will refer to a variable which is local for the considered method? I mean variable which is seen only in this method.

What about this.method()? Can I use it? Should I use it. If I just use method(), will it not be, by default, applied to the current object?

Edit
Report

1 Answer

8

Unless you have overlapping variable names, its really just for clarity when you're reading the code.

answered 2010-03-09T18:00:52.993

Your Answer