简体   繁体   English

eclipse中的冗余超级界面警告

[英]Redundant super interface warning in eclipse

Why could this construct generate an error/warning in Eclipse? 为什么这个构造会在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 . 警告在B中,靠近工具I1

Imaging if class A implement I1 and class B extends A . 如果A类实现I1B类扩展A则成像。 By default B implements I1 even though it does not need to implement any method in I1 . 默认情况下, B实现I1即使它不需要在I1实现任何方法。 If A were to change to implement I2 , B would still compile. 如果A要改为实现I2B仍然会编译。

However, if B explicitly implements I1 but does not provide the methods, then this change would cause B to no longer compile. 但是,如果B显式implements I1但不提供方法,则此更改将导致B不再编译。

Of course, I am ignoring the issues of users of B that might be assuming that B implements I1 . 当然,我忽略了可能假设B实现I1B用户的问题。 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. 它告诉你,你不需要在B中实现任何接口方法,因为它们已经在A中实现了。因此实现接口方法不仅可以实现接口,还可以覆盖超类中的默认实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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