Sonarqube给出了一个修饰符的使用建议,不得不说,sonarqube扫描的还是很全面的,真的是面面俱到,不放过任何一个细节!
————sonarqube 提示开始———–
Since abstract
classes can’t be instantiated, there’s no point in their having public
or internal
constructors. If there is basic initialization logic that should run when an extending class instance is created, you can by all means put it in a constructor, but make that constructor private
or protected
.
Noncompliant Code Example
abstract class Base
{
public Base() // Noncompliant, should be private or protected
{
//...
}
}
Compliant Solution
abstract class Base
{
protected Base()
{
//...
}
}
————sonarqube 提示结束———–
点评:不作任何点评!你平时会注意这个细节么?欢迎留言写出你的感受!