Carey Brown wrote:"this" appears frequently because often there is a parameter name that is identical to a field of the class and "this" clarifies that you are specifically referring to the class field and not a local variable.
Often people just get into a bad habit of adding "this" when it is unnecessary. Those should be removed.
Ammar Pehilj wrote:Yes my bad. I changed the play() method in the album class to print this.playlist instead of getPlaylist. Thank you. I am aware of that, it was among the first things we learnd, but I prefer having them in separate files,
it is easier to browse.
Carey Brown wrote:
I wasn't necessarily advocating that you put it all in one file. When you ask for help in forums it is often easier to help you if there's only a single file to cut-n-paste and if you tweak one class then all the code stays together. When you post multiple changes to various bits and pieces we're no longer sure they're in sync.
Outside of the constructor keyword this can be used in mutator/setter method (Used to set values of private variables), reason of use is same as you used in your constructors i.e. having parameters and class instance field with same name. Example
Ammar Pehilj wrote:I still really don't get when they might be used outside a constructor. Like, if playlist was a parameter of the constructor, then I get it, but otherwise is there a reason to use it?
Ammar Pehilj wrote:It kinda sucks when I have these questions torture me all day, then as soon as I send it to someone, I start noticing my dumb mistakes.
Ganesh Patekar wrote: Outside of the constructor keyword this can be used in mutator/setter method (Used to set values of private variables), reason of use is same as you used in your constructors i.e. having parameters and class instance field with same name. Example