Normally, I use this
in constructors only.
I understand that it is used to identify the parameter variable (by using this.something
), if i
As everyone said, this represents the current object / current instance. I understand it this way, if its just "this" - it returns class object, in below ex: Dog if it has this.something, something is a method in that class or a variable
class Dog {
private String breed;
private String name;
Dog(String breed, String name) {
this.breed = breed;
this.name = name;
}
public Dog getDog() {
// return Dog type
return this;
}
}