Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StringBuffer class

 
Mansi Vyas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All of the StringBuffer methods operate on the value of the StringBuffer objects invoking the method. So why do some of the StringBuffer methods such as append, insert, reverse have StringBuffer as a return type? What is the point of this? The only reason I can think of is so that method calls can be chained to each other. Is this correct? Or am I missing something?
Thanks.
Mansi
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's right, having the method return a reference to the StringBuffer allows you to chain multiple invocations together, like this:
 
Mansi Vyas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are these methods just returning a reference to this (the StringBuffer object invoking the method)?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mansi Vyas:
Are these methods just returning a reference to this (the StringBuffer object invoking the method)?

Yup. In effect, they are performing the desired operation and then doing a "return this".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic