You should not write INTEGER_ONE
! Neither should you write 1
(see exception below)!
Why? A literal like 1
is called a magic number. Magic numbers are "unique values with unexplained meaning or multiple occurrences which could (preferably) be replaced with named constants" (explanation from the same Wikipedia page).
So what usually should be done is making those magic numbers to constants whose name represents or explains the meaning of that number. The constant INTEGER_ONE
does not explain the meaning.
So what you actually have to do is to find the meaning of the value in this context and create a constant with exactly that name. If the 1
represents the maximum number of allowed threads for example, you should have a constant like:
static final int MAX_NUMBER_OF_THREADS = 1;
EDIT as per Tagir's comment
If the literal itself has a meaning in the domain for which you are writing the code, then it should not be replaced by a named constant. Tagir's example for calculating the inverse element is a good one:
double invert(double x) {
return 1/x;
}
Here the literal 1
has a meaning in this context inside the math domain. So it can be used as is.