This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Please explain this line of code to me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please explain this line of code to me" Watch "Please explain this line of code to me" New topic
Author

Please explain this line of code to me

Klaas Vredevort
Greenhorn

Joined: Dec 27, 2005
Posts: 29
I had my program edited by some guy, and he put in the following lines of code:



How come I have to add this.* to the bold lines? Everything else works just fine without it.

Klaas
Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
Originally posted by Klaas Vredevort:
I had my program edited by some guy, and he put in the following lines of code:



How come I have to add this.* to the bold lines? Everything else works just fine without it.

Klaas




Your code might be inside a method, if i am not wrong. because your post is incomplete.

Any way, What i think , there is a variable named wordToPlayWith inside the method, which is local variable. And you also have a class variable with same name wordToPlayWith.

To remove the name conflict we use this . using this.wordToPlayWith refers to your class variable and not your local variable


Lack of will power has caused more failure than lack of intelligence or ability.
My Blog | Red5 Resources | Technology Update | Daily Technology Tips
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

As Sunil Kumar Gupta pointed out above, we would need to know more about the context to say for sure. However, Bruce Eckel notes that...
Some people will obsessively put this in front of every ... field reference, arguing that it makes it "clearer and more explicit." Don't do it. There's a reason that we use high-level languages: They do things for us. If you put this in when it's not necessary, you will confuse and annoy everyone who reads your code...

(Footnote on page 169 of Thinking in Java, 4th edition.)


"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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please explain this line of code to me
 
Similar Threads
Pass a StringBuffer to a method
Adding a usedChar array in my program
StringBuffer
Can somebody explain these lines of code?
Can somebody show me how to implement buttons?