当我进行一个项目时,我发现了一些奇怪的变量名称。 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.