This keyword used to represent the current instance of the class.
Reference: this keyword
Example:
- public class ThisKeyWordExample
- {
- String str = 'Test Me';
- public void strMethod(String str)
- {
- System.debug('--Parameter Value--'+str);
- System.debug('--Current Instance Value--'+this.str);
- }
- }
The above example has One Instance Variable &
One Local Variable or Method parameter with same name(i.e. str).
str = Refers parameter value.
this.str = Refers the current instance variable
value.
To execute this class go to Developer Console, paste the below line then click execute.
- ThisKeyWordExample thisExample = new ThisKeyWordExample();
- thisExample.strMethod('Test You');
Reference: this keyword
This looks similar to Java. "This" keyword is being used everywhere! Alin
ReplyDeleteNice post. this keyword in java .
ReplyDeletethanks