+ 3

Is is necessary to mention "this" keyword for referring current object?

Any alternative for using 'this' keyword

14th Oct 2016, 11:51 AM
Aniket kinhikar
Aniket kinhikar - avatar
3 Answers
+ 5
No alternative. Why would you need one? Think of "this" as an implicit first parameter of any non-static method of your class. You can omit the "this." prefixing for attributes of the class inside a method of the class, providing that there are no parameter or variable of the same name in that method. I would suggest to always write it regardless so that readers of your code (including you) immediately understand that you are manipulating an attribute of the class, and not just a variable.
14th Oct 2016, 12:18 PM
Zen
Zen - avatar
+ 2
you should only really use "this" if you are overloading a variable. otherwise it is basically redundant.
14th Oct 2016, 3:01 PM
Eric Kershner
Eric Kershner - avatar
- 1
No
14th Oct 2016, 12:10 PM
Shafiya Nizam