Skip to content

How to call/use the interface default implementation? #97768

Answered by colejohnson66
TheBlueSky asked this question in Q&A
Discussion options

You must be logged in to vote

Casts are required to call default interface methods (DIMs), as per the specification. To call DIMs, one must be interacting with an interface object, not directly with a class/struct.

Also, casts are free when you're going "up" the inheritance tree (and not boxing); They only "cost" something if you're going "down" the tree (such as from an IService to MyService) as type checking must be performed. In addition, "constrained calls" like you're doing will not box if the original object is a value-type (struct); The JIT will optimize out the boxing in such situations.

https://andrewlock.net/understanding-default-interface-methods/

If you're asking to "forward" the default implementation to …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@TheBlueSky
Comment options

@colejohnson66
Comment options

Answer selected by TheBlueSky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants