InfoQ Homepage News C# Default Interface Methods Update

C# Default Interface Methods Update

This item in japanese


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."

We need your feedback

How might we improve InfoQ for you

Thank you for being an InfoQ reader.

Each year, we seek feedback from our readers to help us improve InfoQ. Would you mind spending 2 minutes to share your feedback in our short survey? Your feedback will directly help us continually evolve how we support you.

Take the Survey

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p


Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.