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.
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
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.)