| Author |
this keyword. optional or compulsive
|
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
|
Is usage of this keyword in JAVA optional or Compulsive?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
It's only required if there would be a naming conflict. The most often occurring example of that is in setters:
Without the "this.", the statement would be an identity assignment of the parameter field to itself.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
|
Note that "this" is also used within a constructor to call an overloaded version of that constructor. (See Java Tutorials - this.)
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56554
|
|
|
And I think you meant compulsory, not compulsive.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4204
|
|
Bear Bibeault wrote:And I think you meant compulsory, not compulsive.
Never seen code where this is used at every opportunity?
|
luck, db
There are no new questions, but there may be new answers.
|
 |
 |
|
|
subject: this keyword. optional or compulsive
|
|
|