interface I
{
void foo();
}
class A : I
{
public override void foo() { } // OK, but should be NG!!
public void foo() { } // OK
}
In this example the use of override is optional,
however since we are not overriding any function it should
be illegal to specify it as override.
Comment #1 by schveiguy — 2013-04-22T10:22:51Z
I would tend to think this is allowed. Imagine if you switched an interface to an abstract base class or vice versa, you wish to make someone go through all their calls and add/remove override?
I had a bug fixed a long time ago, issue 2524.
In a comment, Walter said:
"This is a compiler bug. You can override an interface function."
I'm assuming this still applies today.
Comment #2 by damianday — 2013-04-22T11:03:58Z
(In reply to comment #1)
> I would tend to think this is allowed. Imagine if you switched an interface to
> an abstract base class or vice versa, you wish to make someone go through all
> their calls and add/remove override?
>
> I had a bug fixed a long time ago, issue 2524.
>
> In a comment, Walter said:
>
> "This is a compiler bug. You can override an interface function."
>
> I'm assuming this still applies today.
That's precisely what I was doing when I stumbled upon this, changing a abstract class to a interface. I'm not sure why both are allowed, even though it does no harm to keep both, it seems one should be the right way and the other a warning possibly?
Comment #3 by verylonglogin.reg — 2014-07-18T11:43:05Z
(In reply to Damian from comment #2)
> [snip]
> I'm not sure why both are allowed, even
> though it does no harm to keep both, it seems one should be the right way
> and the other a warning possibly?
One can open an enhancement request for this, but this issue report is invalid.
Comment #4 by code — 2018-02-14T07:27:36Z
Also makes more sense to use override in case we support default methods in interfaces (Java 8) at some point.