rspec/rules/S2135/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

39 lines
1008 B
Plaintext

== Why is this an issue?
The ``++String++`` class has a ``++toString++`` method because ``++Object++`` itself does. I.e. it couldn't not have the method. But having the method doesn't mean it should be used. In fact doing so is worse than pointless since it returns the ``++String++`` itself.
=== Noncompliant code example
[source,java]
----
String str1 = "Now is the time for all good people";
String str2 = str1.toString();
----
=== Compliant solution
[source,java]
----
String str1 = "Now is the time for all good people";
String str2 = str1;
----
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
=== duplicates: S1858
=== on 10 Oct 2014, 11:08:35 Freddy Mallet wrote:
@Ann, my 2 cents:
* I really like this tag "clumsy" :)
* using the toString() method doesn't imply any CPU or memory overhead (just the very low cost of a method call). So I would associate this rule to the category Maintainability > Readability
*
endif::env-github,rspecator-view[]