OPT.USC
Use 'String' instead of 'StringBuffer' for constant strings
Description
This rule flags code where `StringBuffer' is used for a constant string.
Dynamically resizeable strings are not necessary for constant strings.
Example
package OPT;
public class USC {
String method () {
StringBuffer s = new StringBuffer ("Hello");
String t = s + "World!";
return t;
}
}
Repair
Replace `StringBuffer' with `String' if it is certain that the object will not change. This will reduce the overhead and improve performance.
|