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
Simply to demonstrate:
public Animal myMethod(){ if(this isinstanceof Animal){ return new Animal(); } else{ return this.getClass().newInstance(); } }