aspose file tools
The moose likes Java in General and the fly likes StringBuffer in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "StringBuffer in Java" Watch "StringBuffer in Java" New topic
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: StringBuffer in Java
 
Similar Threads
Difference
TreeSet contains "something like this"
problem with inhereitance
Rules declaration in text file - please help
java.lang.ClassCastException