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.
public class Myclass { public final int THRESHOLD = 3; // Non-Compliant }
public class Myclass { public static final int THRESHOLD = 3; // Compliant }
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).