resources.report.rules.pmd.ConsecutiveAppendsShouldReuse.html Maven / Gradle / Ivy
ConsecutiveAppendsShouldReuse
ConsecutiveAppendsShouldReuse
Consecutive calls to StringBuffer/StringBuilder .append should be chained, reusing the target object. This can improve the performance by producing a smaller bytecode, reducing overhead and improving inlining. A complete analysis can be found here
This rule is defined by the following Java class: net.sourceforge.pmd.lang.java.rule.strings.ConsecutiveAppendsShouldReuseRule
Example(s):
String foo = " ";
StringBuffer buf = new StringBuffer();
buf.append("Hello"); // poor
buf.append(foo);
buf.append("World");
StringBuffer buf = new StringBuffer();
buf.append("Hello").append(foo).append("World"); // good