+ 7

What is the use of this keyword ?

19th Feb 2018, 3:19 AM
Ruchit Porwal
Ruchit Porwal - avatar
5 Answers
+ 25
this keyword is used to refer the current object //I saw its use in getter , setter & constructors to initialize the object or take out values of instance members of that object https://www.javatpoint.com/this-keyword
19th Feb 2018, 3:21 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
to specify the CURRENT CLASS variable this.apple nothing else (kinda, most of the time)
19th Feb 2018, 6:39 AM
DeleteThisAccount
+ 2
In Android it is used to refer to your actual activity/fragment without the need to write it out.
19th Feb 2018, 6:40 AM
Bartinho
0
Think about it like this. Letā€™s say that YOU, as a person, are a member of the Person class. You would refer to yourself as ā€œmeā€, right? And that expresses that you are referring to your own person, not some other person, or persons in general. Thatā€™s what ā€œthisā€ is. It is a specific instance of a class referring to itself. (In VB, the functional sister-language of C#, the keyword ā€œmeā€ is used instead of ā€œthisā€.)
22nd Mar 2018, 4:41 PM
Raymond Nagel
Raymond Nagel - avatar