Is there any way to specify that the return value of a method in an abstract class should be of the same type as the containing class?
问题 Suppose I am writing some classes to perform simple mathematical operations, and that I have an abstract class JNumber with a method in it for adding on another number: public abstract class JNumber { public abstract JNumber add(JNumber addend); // etc. } The return value from add represents the sum of this with the parameter addend . Now suppose that I have an abstract subclass (called JFieldElement ) of JNumber which includes a method for division (I cannot have this method in the JNumber