What is the point of the this keyword in this example from Bates and Sierra's book? I tried the example both with and without it and got the same result. So now I'm confused about when to use this inside a method. Can someone give me an example that actually makes a difference in the output?
There is a 3rd use of this, which that link misses out. It can mean the whole object you happen to be in. You cna have a serialising method which writes the entire object to a file with an object output stream or similar:-
The keyword can also help you access same-named variables that have been shadowed in the current scope. In the example below, the 'message' field declared on line 3 is shadowed by the parameter on line 10. Using 'this' on line 11 allows you to access the field instead of the parameter. I think this is kind of where the example you cited was going. Note that this is just an example and you should avoid situations where names are shadowed in real-world code.
In my above example the this keyword doesn't seem necessary because if you take it out you get the same results. Why would the writers include it? And also, I understand that this.coolMethod() refers to the current object that is calling it so it returns "Wow baby" but can anyone explain in which situation would it return something different? I guess that is what I am struggling to understand.