Class name as return type
Posted: Wed May 15, 2019 6:57 pm
Yes, I found another odd code in the blogs while I was looking for examples of garbage collection,
What would be the point of having return type of a method be the of type of its own Class?
( I tried to find something about this type of return in javaDocs, but I didn't see anything more than a here it is!)
Thanks
Code: Select all
public class TestCode {
public TestCode myMethod(){
TestCode tc1 = new TestCode();
TesdtCode tc2 = new TestCode();
return tc1;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
TestCode tc3 = new TestCode().myMethod();
( I tried to find something about this type of return in javaDocs, but I didn't see anything more than a here it is!)
Thanks