
When an include is not surrounded by empty lines, its content is inlined on the same line as the adjacent content. That can lead to broken tags and other display issues. This PR fixes all such includes and introduces a validation step that forbids introducing the same problem again.
51 lines
1.5 KiB
Plaintext
51 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Making a ``++public++`` 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.
|
|
|
|
|
|
Further, when a non-``++public++``, ``++final++`` field isn't also ``++static++``, it implies that different instances can have different values. However, initializing a non-``++static final++`` field in its declaration forces every instance to have the same value. So such fields should either be made ``++static++`` or initialized in the constructor.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
public class Myclass {
|
|
public final int THRESHOLD = 3;
|
|
}
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
public class Myclass {
|
|
public static final int THRESHOLD = 3; // Compliant
|
|
}
|
|
----
|
|
|
|
=== Exceptions
|
|
|
|
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).
|
|
|
|
____
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|