Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Code Conventions: must match pattern '^[a-z][a-zA-Z0-9]*$'

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]*$'.

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?

Thanks for answers.

like image 706
Christoph W. Avatar asked Oct 30 '12 20:10

Christoph W.


3 Answers

^[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.)

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

static final String ADD = "Add text";

Otherwise, use:

final String add = "Add text";
like image 63
Cat Avatar answered Nov 13 '22 15:11

Cat


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.

like image 35
Simon Forsberg Avatar answered Nov 13 '22 14:11

Simon Forsberg


This Regex indicate the need for camelCase with the first letter being small and then every next word having the first letter in it as capital letter.

like image 1
Sam Avatar answered Nov 13 '22 15:11

Sam