aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 19538
    
  16

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???