Redundant final on Static Method
ID |
java.final_on_static_method |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Java |
Tags |
code-style |
Rationale
Static methods are resolved at compile time and cannot be overridden by subclasses — they can only be hidden. Applying final to a static method is therefore redundant and suggests the author may have confused static methods with instance methods. The unnecessary modifier adds noise to the declaration.
// Bad -- final is redundant on a static method
public static final int compute(int x) {
return x * 2;
}
Remediation
Remove the final modifier from the static method.
// Good
public static int compute(int x) {
return x * 2;
}