Example | |
|
Solution |
A non-constant String object should be declared as a StringBuffer instead. Any changes to the String should be done with the append() class of StringBuffer.
|
public class ClassA { private final String stringObject = "A new String"; private StringBuffer nonConstantString = new StringBuffer("Changing String"); public void method() { String localString = "append"; nonConstantString.append(localString); } } |