I'm a newbie in Java. I stumbled upon object reference returns in a method and I had to know what the use of it was. But I couldn't find a clear guide explaining it. I hope you can help.
Sample code:
public class Test{
public Test method(){
//code goes here
return this;
}
}
I've also seen other versions of this return statement like returning a reference variable of a class that is either directly related or not (super-class, etc.) to the class in which the method is in. But I can't wrap my head around what the use of this is? I've seen people use them for accessing and manipulating variables in the class but what else? If possible, could you explain the theory behind it (how it works behind the scenes)? And what the term for this "reference variable return statement in a method" is? And finally, what is the theory behind "return this"?
Thank you!