Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redundant super interface warning in eclipse

Tags:

java

eclipse

Why could this construct generate an error/warning in Eclipse? I understand for what it will generate a report, but I guess there must be some rationale, what can go wrong, if you spell out those redundant super interfaces.

Example:

interface I1{
    void boo();
}


class A implements I1 {
    public void boo() {}
}


class B extends A implements I1 {
    public void boo() {}
}

The warning is in B, near implements I1.

like image 446
pihentagy Avatar asked Aug 16 '26 07:08

pihentagy


2 Answers

Imaging if class A implement I1 and class B extends A. By default B implements I1 even though it does not need to implement any method in I1. If A were to change to implement I2, B would still compile.

However, if B explicitly implements I1 but does not provide the methods, then this change would cause B to no longer compile.

Of course, I am ignoring the issues of users of B that might be assuming that B implements I1. Let's assume for this case that that is not an issue.

like image 81
John B Avatar answered Aug 17 '26 22:08

John B


It's only a warning, and I guess it has two reasons:

  • it's redundant, and can thus be removed. The less noise you have the better it is. But this is a matter of style
  • it tells you that you don't need to implement any of the interface method in B, since they're already implemented in A. And implementing the interface methods would thus not only implement the interface, but also override the default implementation in the superclass.
like image 44
JB Nizet Avatar answered Aug 17 '26 21:08

JB Nizet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!