Jtest logo




Contents  Previous  Next  Index

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.


Contents  Previous  Next  Index

ParaSoft logo
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft