I understand that "this" is a reference to the current object from within each method (it is also a reference to the implicit parameter). However, is there any reason to label the instance variables with "this" for any reason other than readability/style? I haven't found a decent explanation on when and why to use this from google or from the book I'm reading.
Asked
Active
Viewed 25 times
0
-
4One case, which will often occur in constructors and setters, is when there is a local variable with the same name as an instance variable – Matt Nov 12 '18 at 03:48
-
This is something I have seen. I now realize I haven't ever passed arguments to my constructors with the same name as my instance variables. Is this commonly used as well within method parameters? – Caleb Suhy Nov 12 '18 at 03:54
-
`this.outerClassName` can be used in lambdas and anonymous classes to reference the outer class instance. This can lead to memory leaks. – MeetTitan Nov 12 '18 at 05:39