解决Java Checkstyle错误:名称'logger'必须匹配模式'^ [A-Z] [A-Z0-9] *(_ [A-Z0-9] +)* $' [英] Resolve Java Checkstyle Error: Name 'logger' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'
问题描述
使用Eclipse Checkstyle插件我看到这个错误:
Using the Eclipse Checkstyle plugin I see this error:
名称'logger'必须匹配模式
'^ [AZ] [A-Z0-9] *(_ [A-Z0-9] +)* $'
。
我通过更改以下方法解决了此错误:
I resolved this error by changing:
private static final Logger logger = Logger.getLogger(someClass.class) / code>
private static final Logger logger = Logger.getLogger(someClass.class);
到
private static final Logger LOGGER = Logger .getLogger(someClass.class);
为什么这是一个checkstyle警告?
推荐答案
因为该字段被标记为 final
和 static
这意味着它是一个常量,应以大写字母命名。
Because the field is marked final
and static
which implies that it's a constant and should be named with uppercase letters.
从此链接,您可以看到模块 ConstantName
格式为 ^ [AZ] [A-Z0- 9] *(_ [A-Z0-9] +)* $
这正是一个您的Checkstyle插件已指定。
From this link, you can see that the module ConstantName
has the format ^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$
which is exactly the one your Checkstyle plugin has specified.
这篇关于解决Java Checkstyle错误:名称'logger'必须匹配模式'^ [A-Z] [A-Z0-9] *(_ [A-Z0-9] +)* $'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!