rspec/rules/S2116/java/rule.adoc
2022-02-04 16:28:24 +00:00

41 lines
984 B
Plaintext

While ``++hashCode++`` and ``++toString++`` are available on arrays, they are largely useless. ``++hashCode++`` returns the array's "identity hash code", and ``++toString++`` returns nearly the same value. Neither method's output actually reflects the array's contents. Instead, you should pass the array to the relevant static ``++Arrays++`` method.
== Noncompliant Code Example
[source,java]
----
public static void main( String[] args )
{
String argStr = args.toString(); // Noncompliant
int argHash = args.hashCode(); // Noncompliant
----
== Compliant Solution
[source,java]
----
public static void main( String[] args )
{
String argStr = Arrays.toString(args);
int argHash = Arrays.hashCode(args);
----
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[]