I am getting a warning related to one of my fields declarations, and wanted to know what would be good practice to deal with it
public class ModeloCatalogo extends Modelo {
private static ArrayList<String> excluidas = new ArrayList<>();
...bunch of irrelevant fields...
private static void functionThatLoadsValuesIntoArrayList(){
excluidas.add("String 1");
...
excluidas.add("String n");
}
...bunch of irrelevant methods...
}
In the field declaration, netbeans warns "field can be final", which can be solved like:
private static ArrayList<String> EXCLUIDAS = new ArrayList<>();
Please note that if is not uppercase, netbeans generates a different warning due to naming conventions. (added in edit for clarity)
It should be uppercase as for naming conventions which makes me cringe, doesn't seem right.
Got rid of the warning by initializing the array inside the function that loads values into array.
private static ArrayList<String> excluidas;
private static void functionThatLoadsValuesIntoArrayList(){
excluidas = new ArrayList<>();
excluidas.add("String 1");
...
But it decreases code readability IMHO.
So it got me thinking, what is the correct way to get rid of the warning?