Lack of override for implementing default interface methods can introduce errors #2757
Unanswered
jpobst
asked this question in
Language Ideas
Replies: 1 comment
-
I don't think that C# could change the using System;
public interface IFoo {
void M();
}
public class Bar {
public virtual void M() => Console.WriteLine("Hello!");
}
public class Baz : Bar, IFoo {
public void M() => Console.WriteLine("Goodbye!");
}
static class Program {
public static void Main() {
Bar b = new Baz();
b.M();
}
} The above will print "Goodbye", but if you add But C# could take a similar tactic to Java in that an attribute could be used along with an analyzer that would ensure that the method did in fact implement an interface member. I would agree that it sounds like the tooling needs some changes to work well with DIM. The default members should be discoverable. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When using default interface methods, the fact that classes implementing the interface do not
override
the interface method leads to subpar compile-time checking and IDE support.For example, this typo is not caught by the compiler:
Java catches this mistake using the @OverRide keyword:
results in:
Additionally this means that implementing default interface methods in a class does not participate in the IDE tooling one expects.
override
in the implementing class, the default interface method does not appear in Intellisense.Beta Was this translation helpful? Give feedback.
All reactions