综合编程

C# Default Interface Methods Update

微信扫一扫,分享到朋友圈

C# Default Interface Methods Update
0

As support for Default Interface Methods
gets closer to completion, potential issues were raised
. While much has been accomplished, this is a complex feature and many of the specifics haven’t been settled yet. But to begin with, here are some of the resolved questions.

Static and const fields will be allowed in interfaces.

Operators, other than == and !=
, may be implemented in interfaces. Operators defined on the class always take priority over operators defined in an interface, even if the latter are more specific. Likewise, applicable operators in an interface shadow operators in a base interface.

It is now possible to skip classes when invoking a base class method, confirming the below statement.

We think we approved using the new base(Type) syntax where Type is a class type (e.g. to skip a base and invoke your base's base), but we should explicitly confirm that. Also we should confirm that base(Type).M() might refer to a non-virtual member M. Also we should confirm that there is an accessibility requirement: the M found by this lookup must be accessible where the invocation occurs (i.e. the usual name-lookup constraint).

There is still some doubt about the ability to declare protected methods in interfaces, though it remains tentatively approved.

When a class implements a method, but its subclass marks it as abstract, this is called “reabstraction”. This is needed for Java interoperability, but the exact syntax is still not settled. Essentially the question is whether or not the abstract keyword is required. Also, they, “need to ensure the runtime [team] agrees to implement reabstraction”.

Normal properties in interfaces are abstract, even though they look like auto-implemented properties in classes. But if the property is static, it can’t be abstract. Does that mean a static property declared in an interface is auto-implemented by default?

Partial methods in classes are assumed to be private, as they don’t have an accessibility modifier. But in an interface, a missing accessibility modifier implies the method is public. What is the rule for partial methods in interfaces? Do they allow, disallow, or require the private keyword?

Inside a default method, should object.MemberwiseClone() be accessible?

Finally, should the official name of the feature be called RuntimeFeature.DefaultInterfaceImplementation? Answer, "The LDM doesn’t care what its name is."

阅读原文...


微信扫一扫,分享到朋友圈

C# Default Interface Methods Update
0

InfoQ

Dew Drop – June 14, 2019 (#2980)

上一篇

Aggregation and Grouping in Pandas explained by Experts

下一篇

评论已经被关闭。

插入图片

热门分类

往期推荐

C# Default Interface Methods Update

长按储存图像,分享给朋友