Why can't an interface implementation return a more specific type?

前端 未结 3 1947
难免孤独
难免孤独 2021-01-07 16:18

If an interface specifies a property or method to return another interface, why is it not allowed for implementations of the first interface to \"change\" the return type in

3条回答
  •  离开以前
    2021-01-07 16:58

    It was not implemented, because they didn't feel like the feature would justify the effort. But there are good news.

    This feature has been announced in a post by Mads Torgersen in March 2020, for the upcomming C# 9.0

    abstract class Animal
    {
        public abstract Food GetFood();
        ...
    }
    class Tiger : Animal
    {
        public override Meat GetFood() => ...;
    }
    

提交回复
热议问题