Why do not the constants in the File class follow the constants convention?

6

The convention for constants in Java says that a constant must be declared with uppercase letters and the words should be separated by underscore (_).

The declaration of a constant is done by the sequence of the keywords static and final . Ex: public static final String NOME_COMPLETO = "José da Silva";

The class File has its constants declared in camelCase . That is, it does not follow the convention. Many other Oracle classes follow the convention.

Why is this different? Are there any other conventions that "override" this? Or was the convention ignored?

    
asked by anonymous 10.07.2017 / 14:51

1 answer

7

Actually these variables are not constants, they are variables with a final reference, probably obtained when this class is used, since the separator is defined according to the operating system being executed.

This becomes more obvious by looking at class source , as these variables are declared:

public static final char pathSeparatorChar = fs.getPathSeparator();

public static final String pathSeparator = "" + pathSeparatorChar;

public static final String separator = "" + separatorChar;

public static final char separatorChar = fs.getSeparator();

Notice that separatorChar and pathSeparatorChar has its reference values retrieved from FileSystem , which is the class that stores information about the local file system of the system where the compiler is running.

So, these variables ended up following the convention pattern of variables camelCase , since they are not constants.

As you can see this documentation link , there is a list containing all the constants of the java API, and you can see that they all follow the nomenclature pattern for constants, and the variables of class File are not in this list.

References:

10.07.2017 / 15:22