rspec/rules/S3024/java/rule.adoc

35 lines
719 B
Plaintext
Raw Permalink Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
The use of a ``++StringBuilder++`` or ``++StringBuffer++`` is supposed to make ``++String++`` assembly more efficient than plain concatenation. So don't ruin the effect by concatenating the arguments to ``++append++``.
=== 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
----
StringBuilder sb = new StringBuilder();
sb.append("foo is: " + getFoo()); // Noncompliant
----
=== 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
----
StringBuilder sb = new StringBuilder();
sb.append("foo is: ").append(getFoo());
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
"append" each concatenated value separately.
endif::env-github,rspecator-view[]