Covariant returns for interfaces #4372
Replies: 3 comments 1 reply
-
I absolutely agree but wouldn't make more sense to put it in as a proposal? |
Beta Was this translation helpful? Give feedback.
-
I think the issue here is simply that the runtime didn't add support for it. I think it would be worth raising with the runtime team why that is and whether there are any plans to change that. |
Beta Was this translation helpful? Give feedback.
-
Interestingly, it's in the proposal. That does include the line
So I wonder whether that was an explicit decision in order to keep backwards compat, but I've failed to find any discussion on that. |
Beta Was this translation helpful? Give feedback.
-
C# 9 has allowed covariant return types for classes. It would be very useful to have the same extend to interfaces, as the use of this feature is often blocked when implementing an interface.
Currently, the following is allowed
but doing this is not:
In the above, the IDerived doesn't actually "override" parent interface - it adds an additional method.
Additionally, Covariant return for concrete types does not work with Generics. The following is currently invalid:
Beta Was this translation helpful? Give feedback.
All reactions