CODSTA.USN
Use symbolic names for constants
Description
This rule flags code that uses an unnamed constant.
Named constants (final static variables) make the code much easier to understand and maintain. To avoid reporting too many spurious errors, Jtest will not report an error for the following integer constants:
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Jtest will only give one error per constant found in the code.
Example
package CODSTA;
class USN {
private int[] getArray () {
return new int [1000];
}
}
Repair
class USN {
private int[] getArray () {
return new int [ARRAY_SIZE];
}
private static final int ARRAY_SIZE = 1000;
}
|