rspec/rules/S2786/java/rule.adoc

89 lines
1.8 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
According to http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.9[the Java Language Specification-8.9]:
____
Nested enum types are implicitly ``++static++``.
____
So there's no need to declare them ``++static++`` explicitly.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public class Flower {
static enum Color { // Noncompliant; static is redundant here
RED, YELLOW, BLUE, ORANGE
}
// ...
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public class Flower {
enum Color { // Compliant
RED, YELLOW, BLUE, ORANGE
}
// ...
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this redundant "static" qualifier; nested enum types are implicitly static.
=== Highlighting
Primary Location: the 'static' keyword
Secondary Location: the 'enum' keyword
'''
== Comments And Links
(visible only on this page)
=== on 31 Mar 2015, 15:09:56 Nicolas Peru wrote:
\[~ann.campbell.2]could be nice to add a link or a quote from the jls : \http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.9
____
Nested enum types are implicitly static. It is permissible to explicitly declare a nested enum type to be static.
____
=== on 31 Mar 2015, 17:46:06 Ann Campbell wrote:
\[~nicolas.peru] why would we quote the docs as saying it's permissible to do exactly what this rule says not to do?
=== on 1 Apr 2015, 08:42:30 Nicolas Peru wrote:
Then let's just keep the first part of the sentence :
____
Nested enum types are implicitly static.
____
point is to refer to the correct section of the JLS to let user know we did not invent this.
=== on 1 Apr 2015, 17:06:42 Ann Campbell wrote:
Done [~nicolas.peru]
endif::env-github,rspecator-view[]