This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes immutable??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "immutable???" Watch "immutable???" New topic
Author

immutable???

Varun Goenka
Ranch Hand

Joined: Mar 09, 2009
Posts: 37
I just heard the word somewhere.
In reference of the string class.


From The Demon,
with love.
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
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.


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
Yes, set. Thank you.

There needs to be a no posting before caffeine rule.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: immutable???