Inheritance from multiple interfaces with the same method name

Q. Schroll qs.il.paperinik at gmail.com
Wed Dec 6 23:56:33 UTC 2017


Say I have two interfaces
     interface I { void f(); }
and
     interface J {  int f(); }
implemented by some class
     class A : I, J {
         // challenge by the compiler:
         // implement f()!
     }

VB.NET allows that by renaming the implementation (it does allow 
it generally, not only in the corner case).
C# allows that by specifying the target interface when 
implementing (can be omitted for exactly one; corner case 
handling); the specification makes the implementation private. 
(See [1])
Java just disallows the case when two methods are incompatible. 
If they are compatible, they must be implemented by the same 
method. If they are meant to do different things, you are screwed.

What is D's position on that? The interface spec [2] does not say 
anything about that case.


[1] 
https://stackoverflow.com/questions/2371178/inheritance-from-multiple-interfaces-with-the-same-method-name
[2] https://dlang.org/spec/interface.html


More information about the Digitalmars-d mailing list