java - 使用 $ char 设置某些变量的名称是否正确?

标签 java variables sonarqube

<分区>

当我进行一个项目时,我发现了一些奇怪的变量名称。 Sonarqube 为我提供了关于这些变量的 Code Smell 语句。

例如protected String value$editedby$java$lang$String;

来自 Sonarqube 的消息:

Rename this field "value$editedby$java$lang$String" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

那么在变量名中使用 $ 是正确的方法吗?

最佳答案

我强烈反对,JLS-3.8. Identifiers说(部分)

The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $ sign should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems.

关于java - 使用 $ char 设置某些变量的名称是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41429481/

相关文章:

适用于 Windows 7 和 Windows 10 的 Java 程序

java - 将图像绘制为多边形

python - 将变量传递给正在导入的文件?

javascript - Jenkins sonarqube 插件无法分析文件

c# - 误报 : Fix this implementation of IDisposable to conform to the dispose pattern

c# - Sonar "Invalid character encountered in file"未分析的一些文件

java - 为 Java 客户端实现故障转移模式的最佳方法

java - 十进制格式 "Multiple decimal separators in pattern"

android - 无法分配局部变量,因为它是在外部定义的

variables - 仅当条件为真时,如何在 go 中创建变量?