rspec/rules/S1195/java/rule.adoc
Irina Batinic 1527b398e6
Modify rule S1195: Update rule according to the LayC (#1999)
Co-authored-by: ADarko22 <angelo.buono@sonarsource.com>
2023-06-01 15:26:51 +02:00

54 lines
1.5 KiB
Plaintext

== Why is this an issue?
Placing the array designators `[]` after the type helps maintain backward compatibility with older versions of the Java SE platform.
This syntax contributes to better readability as it becomes easier to distinguish between array types and non-array types.
It helps convey the intention of the method to both the developer implementing it and the developer using it.
=== Noncompliant code example
[source,java,diff-id=1,diff-type=noncompliant]
----
public class Cube {
private int magicNumbers[] = { 42 }; // Noncompliant
public int getVector()[] { /* ... */ } // Noncompliant
public int[] getMatrix()[] { /* ... */ } // Noncompliant
}
----
=== Compliant solution
[source,java,diff-id=1,diff-type=compliant]
----
public class Cube {
private int[] magicNumbers = { 42 }; // Compliant
public int[] getVector() { /* ... */ } // Compliant
public int[][] getMatrix() { /* ... */ } // Compliant
}
----
== Documentation
* https://docs.oracle.com/javase/specs/jls/se20/html/jls-10.html[Oracle Java Language Specification] - Arrays
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Move the array designators "[]" to the end of the return type.
'''
== Comments And Links
(visible only on this page)
=== relates to: S1197
=== on 18 Aug 2013, 14:42:53 Freddy Mallet wrote:
Is implemented by \http://jira.codehaus.org/browse/SONARJAVA-294
endif::env-github,rspecator-view[]