| Author |
StringBuffer in Java
|
Prasanna Kannan
Greenhorn
Joined: Mar 07, 2005
Posts: 21
|
|
Hello, I was using a final variable to store a StringBuffer object; I was thinking that Java should not allow me to append that StringBuffer, as the variable that holds this StringBuffer is final. But, I'm surprised to see that Java allows me to do that. See below the example. public final StringBuffer s = new StringBuffer("Text1"); s.append(" Text2"); System.out.println(" S = " + s); The above lines of code compiles fine and gives the output Text1 Text2. Can anyone explain this behavior for me, please? Regards, Prasanna
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
|
Declaring a reference final means that you can't point it to another object. It does not prevent you from changing the contents of the object.
|
 |
Prasanna Kannan
Greenhorn
Joined: Mar 07, 2005
Posts: 21
|
|
Thank you Keith . I got it.
|
 |
 |
|
|
subject: StringBuffer in Java
|
|
|