+ 2
Where to use "this" keyword in java?
I am getting confuse where to use "this" keyword in program
2 Respostas
+ 4
Whenever you call 'this' you are handling the object calling the method. In Java almost everything is an object, so you will be calling the method of an object, on an object. To get the reference of the calling object in the method you use 'this'.
It's also useful to distinguish code when an ambiguity might be present. for instance:
public void set(int param) {
this.param = param;
}
left side of equals refers to the class variable, right side refers to the local method parameter
+ 2
In short, this means -
if you put this in MainActivity class
that means,
MainActivity.this (that class itself)..