aspose file tools
The moose likes Beginning Java and the fly likes this keyword. optional or compulsive Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "this keyword. optional or compulsive" Watch "this keyword. optional or compulsive" New topic
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
    
  14

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
    
    3

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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: this keyword. optional or compulsive
 
Similar Threads
create jar problem: jarFile.jar: no such file or directory
interface
WA #1.....word association
outer join in DB2
finally null variables