在 SONAR 中进行方法覆盖时出现的小问题

Minor Issue when doing method overriding in SONAR

方法一:问题是

描述受让人资源新问题 - 无用的重写方法:重写方法仅调用 super - 覆盖 A.executeImpl

class A {

protected void executeImpl(){
 // blah blah
}}

class B extends A{

protected void executeImpl(){

super.executeImpl();
}}

class C{

@Inject B b;

protected void executeCall(){

b.executeImpl();
}
}

如果我删除覆盖的方法: Java 错误: 来自类型 B 的方法 executeImpl() 不是 可见

class A {

protected void executeImpl(){
 // blah blah
}}



class B extends A{

}



class C{

@Inject B b;

protected void executeCall(){

b.executeImpl();
}
}

我应该采取什么方法来消除声纳小问题。

我会说你必须重新考虑你的包结构。我认为 ABC 在另一个包中。因此 C 无法访问 A 中的受保护方法,但如果您在 B 中覆盖它,C 可以访问它。

  • 您可以在 A 中制作 executeImpl() public。
  • ABC 全部移动到同一个包或
  • 忽略此问题或将其标记为错误 积极的解释。