- It’s often used in return statements when you want to return the reference to the current object.
- It is also useful for passing the current object to another method.
- When you write several constructors for a class, there are times when you’d like to call one constructor from another to avoid duplicating code. You can make such a call by using the this keyword.
While you can call one constructor using this, you cannot call two. In addition, the constructor call must be the first thing you do, or you’ll get a compiler error message. - Avoid conflict with member variable from method auto variable
this.s = s;
Where the first s is member, the second is a auto variable in a method.
Sunday, September 26, 2010
The use of "this"
The this keyword is used only for those special cases in which you need to explicitly use the reference to the current object.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment