众所周知,Java 中存在默认的可见性修饰符。据我了解,此修饰符可以像其他修饰符一样使用。但为什么 SonarQube 将默认修饰符标记为漏洞 - 明确声明“var”的可见性?
最佳答案
看看the rule的描述.
Failing to explicitly declare the visibility of a member variable could result it in having a visibility you don't expect, and potentially leave it open to unexpected modification by other classes.
如果你有一个类包的私有(private)属性,那么同一个包中的任何类都可以修改这个属性。
但是 Package private 仍然有有效的用途。例如,您可能希望将一个类声明为私有(private)包,这样它就可以在声明它的包内使用,但仍对公共(public)使用隐藏。
关于java - SonarQube 漏洞 : Explicitly declare the visibility for variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54939863/