В Java, при реализации интерфейса, я могу использовать дочерний тип в возвращаемом значении, а в C# не могу.
Java
class Fruit {
}
class Apple extends Fruit {
}
interface IBasket {
Fruit getFruit();
}
class Basket implements IBasket {
private Apple fruit;
@Override
public Apple getFruit() {
return fruit;
}
}C#
class Fruit
{
}
class Apple : Fruit
{
}
interface IBasket
{
Fruit GetFruit();
}
class Basket: IBasket
{
private Apple fruit;
// Method 'GetFruit' cannot implement method from interface 'IBasket'. Return type should be 'Fruit'.
public Apple GetFruit()
{
return fruit;
}
}