简体   繁体   中英

Redundant super interface warning in 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 .

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM