Replies: 4 comments 37 replies
-
The |
Beta Was this translation helpful? Give feedback.
-
One is an override (where variance is supported). One is an implementation, where it is not. If you wanted it supported, it would need a proposal and specification for how it worked (either with runtime support, or a stub method emitted). |
Beta Was this translation helpful? Give feedback.
-
One workaround here would be to explicitly implement the interface member, then declare an additional member which is "the same, but covariant". This is essentially manually implementing the "stub method" which was suggested in #8541 (reply in thread). interface ITreeNode
{
ITreeNode Parent { get; }
IReadOnlyList<ITreeNode> Children { get; }
}
class TreeNodeInt : ITreeNode
{
ITreeNode ITreeNode.Parent => Parent;
public TreeNodeInt Parent { get; }
IReadOnlyList<ITreeNode> ITreeNode.Children => Children;
public IReadOnlyList<TreeNodeInt> Children { get; }
} |
Beta Was this translation helpful? Give feedback.
-
Looks like this feature was already discussed in #49 and added to the proposal, but the part about covariance in interfaces was not implemented. The reason is unclear. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This code works.
This code doesn't compile.
Why doesn't it work in the second case?
Beta Was this translation helpful? Give feedback.
All reactions