Java代码约定:必须匹配模式”^[a - z][a-zA-Z0-9]*美元”

时间:2022-03-15 16:47:45

i would like to use the following constant:

我想使用以下常数:

final String ADD = "Add text";

But my CheckStyle tool tells me that 'ADD' does not match the pattern '^[a-z][a-zA-Z0-9]*$'.

但是我的CheckStyle工具告诉我,‘添加’不匹配模式”^[a - z][a-zA-Z0-9]*美元”。

Could anyone please tell me what is wrong with 'ADD'? Means '^[a-z][a-zA-Z0-9]*$' that every name has to start with a low character? Is there no other possibility?

有人能告诉我“ADD”有什么问题吗?意味着“^[a - z][a-zA-Z0-9]*美元”开始,每个名字都有较低的性格?没有其他的可能性了吗?

Thanks for answers.

谢谢你的答案。

2 个解决方案

#1


14  

^[a-z][a-zA-Z0-9]*$

This regex describes something which starts with lowercase and the remainder is composed of uppercase, lowercase, and numbers. (Examples: aVariable, variable, aNewVariable, variable7, aNewVariable7.)

这个regex描述了以小写开头的内容,其余部分由大写、小写和数字组成。(例子:aVariable, variable, aNewVariable, variable7, aNewVariable7。)

If you want your field to be constant and static, use:

如果你想让你的领域保持恒定和静态,使用:

static final String ADD = "Add text";

Otherwise, use:

否则,使用:

final String add = "Add text";

#2


5  

If it is a constant you want, it should also be static

如果它是一个你想要的常数,它也应该是静态的。

static final String ADD = "Add text";

Constants normally use uppercase letters, but since your variable was not static, it was not interpreted as a constant.

常量通常使用大写字母,但是由于您的变量不是静态的,所以它没有被解释为常量。

#1


14  

^[a-z][a-zA-Z0-9]*$

This regex describes something which starts with lowercase and the remainder is composed of uppercase, lowercase, and numbers. (Examples: aVariable, variable, aNewVariable, variable7, aNewVariable7.)

这个regex描述了以小写开头的内容,其余部分由大写、小写和数字组成。(例子:aVariable, variable, aNewVariable, variable7, aNewVariable7。)

If you want your field to be constant and static, use:

如果你想让你的领域保持恒定和静态,使用:

static final String ADD = "Add text";

Otherwise, use:

否则,使用:

final String add = "Add text";

#2


5  

If it is a constant you want, it should also be static

如果它是一个你想要的常数,它也应该是静态的。

static final String ADD = "Add text";

Constants normally use uppercase letters, but since your variable was not static, it was not interpreted as a constant.

常量通常使用大写字母,但是由于您的变量不是静态的,所以它没有被解释为常量。