Is there any elegant way to make Java method located within parent class return object of child class, when this method is called from child class object?
I want to
public class Parent { public Parent myMethod(){ return this; } } public class Child extends Parent {}
And invoke it like
Parent c = (new Child()).myMethod(); System.out.println(c.getClass());
Is this solution is correct? If it is, then, how is it different from the #1 solution?