rspec/rules/S3024/java/rule.adoc

30 lines
656 B
Plaintext
Raw Normal View History

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++``.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
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
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
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)
include::message.adoc[]
endif::env-github,rspecator-view[]