I’m just curious about the use of this, because the sample code and documentation of Android don’t make use of the this keyword (I like to believe that the android engineers are generally smart, thus my using them as a basis). I’m just curious about the underlying reason that the android engineers don’t make use of this much.
I’m just curious about the use of this , because the sample code and
Share
Its mainly a stylistic difference. I’ve yet to see a argument as to why its good or bad. Personally I like to use it and there are a few instances when you need to use it.
For example if you have a Anonymous Inner class that wants to call a method of the parent class you need
this. Example:Another reason to use
thisis if a method argument masks a member variable. In that case you can usethisto distinguish between the two, although I’d recommend you rename the argument to something that is non masking.Another reason to use
thisis when passing a pointer to the current class instance from within that instance. An example of this is when you create a newIntentThere are probably more places where you’ll need to use
this. These are the first few that came to mind.