java 以下声纳问题的解决方案?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15700280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 20:33:39  来源:igfitidea点击:

Solution for following sonar Issue?

javasonarqube

提问by Ruchira Gayan Ranaweera

following line of code in my code segment detected as an Issue by sonar.

我的代码段中的以下代码行被声纳检测为问题。

code segment:

代码段:

final int Pending=1; 

sonar Issue:

声纳问题:

             Name 'Pending' must match pattern '^[a-z][a-zA-Z0-9]*$'.
             Name 'Pending' must match pattern '^[a-z][a-zA-Z0-9]*$'.

why sonar detect this as an issue?

为什么声纳检测到这是一个问题?

回答by Fabrice - SonarSource Team

Well, Sonar gives an explicit message for the violation: the variable "Pending" does not match the given regexp pattern "^[a-z][a-zA-Z0-9]*$". This pattern means: any string that begins with a lowercase letter, followed by any letters or digits. So your variable should be called "pending", not "Pending".

好吧,Sonar 为违规提供了明确的消息:变量“Pending”与给定的正则表达式模式“^[az][a-zA-Z0-9]*$”不匹配。此模式表示:任何以小写字母开头,后跟任何字母或数字的字符串。所以你的变量应该被称为“待定”,而不是“待定”。

What's more, as Juvanis said, this is the standard naming convention for variables in Java.

更重要的是,正如 Juvanis 所说,这是 Java 中变量的标准命名约定。