rspec/rules/S2116/java/rule.adoc

24 lines
704 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
public static void main( String[] args )
{
String argStr = args.toString(); // Noncompliant
int argHash = args.hashCode(); // Noncompliant
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
public static void main( String[] args )
{
String argStr = Arrays.toString(args);
int argHash = Arrays.hashCode(args);
----