• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

immutable???

 
Varun Goenka
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just heard the word somewhere.
In reference of the string class.
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Immutable means that the object value can not be changed.

It has no mutator methods, which in Java traditionally starts with set.

Any methods in the String class that alter the current String, returns a reference to a new String. It seems wasteful to me to have all that overhead, but if your program needs to make a lot of changes StringBuffer is mutable.

I am not sure why they decided on this, but they were determined to keep it immutable so they made the class final as well.
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rusty Shackleford wrote:It has no mutator methods, which in Java traditionally starts with 'get'.

You mean 'set'. Methods that start with 'get' (accessor methods) are quite frequently used with immutable objects.
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, set. Thank you.

There needs to be a no posting before caffeine rule.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic