Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java final array lowercase or uppercase

I understand that clean code convention requires that final variables be ALL_CAPS in Java. But what if my variable is an array? Must it be all caps? As in which one of the following is best practice:

public static final String[] MY_ARRAY = {"A", "B"};
//...
String str = MY_ARRAY[0];

Or

public static final String[] myArray = {"A", "B"};
//...
String str = myArray[0];
like image 385
Katedral Pillon Avatar asked Mar 25 '15 20:03

Katedral Pillon


1 Answers

No Java code conventions that I'm aware of advocates that all final variables should be all caps. Constants should be all caps, and by constants you usually refer to final fields that are immutable (or deliberately never mutated).

In this case you're using an array, and since it public it may very well be mutated. For this reason, I wouldn't count this as a constant, and therefor go with myArray.

For reference, here's a quote from the Official Oracle Java Code Conventions:

The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores (“_”). (ANSI constants should be avoided, for ease of debugging.)

like image 63
aioobe Avatar answered Oct 20 '22 09:10

aioobe