rspec/rules/S1220/java/rule.adoc

54 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
According to the Java Language Specification:
____
Unnamed packages are provided by the Java platform principally for convenience when developing small or temporary applications or when just beginning development.
____
To enforce this best practice, classes located in default package can no longer be accessed from named ones since Java 1.4.
=== 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 MyClass { /* ... */ }
----
=== 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
----
package org.example;
public class MyClass{ /* ... */ }
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Move this file to a named package.
'''
== Comments And Links
(visible only on this page)
=== on 20 Aug 2013, 20:09:41 Freddy Mallet wrote:
Is implemented by \http://jira.codehaus.org/browse/SONARJAVA-310
=== on 16 Nov 2015, 11:40:10 Michael Gumowski wrote:
I removed reference to PMD rule "DefaultPackage", which is not describing the same case (forbid usage of package visibility for members, see RSPEC-1784 and RSPEC-2072)
endif::env-github,rspecator-view[]