org.sonar.l10n.java.rules.squid.S1170.html Maven / Gradle / Ivy
The newest version!
Making a constant just final
as opposed to static final
leads to duplicating its value for every instance of the class, uselessly increasing the amount of memory required to execute the application.
Noncompliant Code Example
public class Myclass {
public final int THRESHOLD = 3;
}
Compliant Solution
public class Myclass {
public static final int THRESHOLD = 3; // Compliant
}
Exceptions (for Java)
No issues are reported on final fields of inner classes whose type is not a primitive or a String. Indeed according to the Java specification:
An inner class is a nested class that is not explicitly or implicitly declared static. Inner classes may not declare static initializers (§8.7) or member interfaces. Inner classes may not declare static members, unless they are compile-time constant fields (§15.28).
© 2015 - 2025 Weber Informatics LLC | Privacy Policy