rspec/rules/S3066/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

69 lines
1.3 KiB
Plaintext

== Why is this an issue?
``++enum++``s are generally thought of as constant, but an ``++enum++`` with a ``++public++`` field or ``++public++`` setter is non-constant. Ideally fields in an ``++enum++`` are ``++private++`` and set in the constructor, but if that's not possible, their visibility should be reduced as much as possible.
=== Noncompliant code example
[source,java]
----
public enum Continent {
NORTH_AMERICA (23, 24709000),
// ...
EUROPE (50, 39310000);
public int countryCount; // Noncompliant
private int landMass;
Continent(int countryCount, int landMass) {
// ...
}
public void setLandMass(int landMass) { // Noncompliant
this.landMass = landMass;
}
----
=== Compliant solution
[source,java]
----
public enum Continent {
NORTH_AMERICA (23, 24709000),
// ...
EUROPE (50, 39310000);
private int countryCount;
private int landMass;
Continent(int countryCount, int landMass) {
// ...
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
* Lower the visibility of this setter or remove it altogether.
* Lower the visibility of this field.
'''
== Comments And Links
(visible only on this page)
=== on 16 Jun 2015, 13:18:04 Nicolas Peru wrote:
Looks good
endif::env-github,rspecator-view[]