If I have the following interfaces and classes:
public interface IPopulationUnit<T>
{
IPopulationUnit<T> Breed();
}
public abstract class PopulationUnit<T>:IPopulationUnit<T>
{
public abstract PopulationUnit<T> Breed();
}
And then I have an implementation
class StringUnit : PopulationUnit<string>
{
public override StringUnit Breed()
{
}
}
The code doesn't compile because the Breed
method does not match the type IPopulationUnit<string>
but technically doesn't it? I mean, StringUnit
itself is PopulationUnit<string>
which itself is IPopulationUnit<string>
so I would think it would work.
How can I restrict StringUnit
Breed
method to only return type StringUnit
but obey the inheritance rules?