How can I force the base methods to accept in the same concrete instance of the subclass when overriding the subclass?
i.e:.
abstract class Animal { def mateWith(that: Animal) } class Cow extends Animal { override def mateWith...? }
Logically, Cow should be able to mateWith only Cow . However, if I do override def mateWith(that: Cow) , this does not actually override the base class method (which I want, since I want to ensure it exists in a subclass).
I can check to make sure the other instance is of type Cow, and throw an exception if this is not the case - is this my best option? What if I have more animals? I would have to repeat the exception code.
override inheritance scala
Kevin li
source share