The Artima Developer Community
Sponsored Link

News & Ideas Forum (Closed for new topic posts)
Java Theory and Practice: To Mutate or not to Mutate?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Stanley Kohut

Posts: 59
Nickname: velcro
Registered: Mar, 2003

Java Theory and Practice: To Mutate or not to Mutate? Posted: Mar 24, 2003 10:08 PM
Reply to this message Reply
Advertisement
Brian Goetz writes "Immutable objects have a number of properties that make working with them easier, including relaxed synchronization requirements and the freedom to share and cache object references without concern for data corruption. While immutability may not necessarily make sense for all classes, most programs have at least a few classes that would benefit from being immutable."

Read the full IBM DeveloperWorks article here:

http://www-106.ibm.com/developerworks/java/library/j-jtp02183.html

Here's an excerpt:

Immutable classes, when used properly, can greatly simplify programming. They can only be in one state, so as long as they are properly constructed, they can never get into an inconsistent state. You can freely share and cache references to immutable objects without having to copy or clone them; you can cache their fields or the results of their methods without worrying about the values becoming stale or inconsistent with the rest of the object's state. Immutable classes generally make the best map keys. And they are inherently thread-safe, so you don't have to synchronize access to them across threads.

When do you use immutable objects in designs?

Topic: McNealy: Rattling Cages is Good for Sun Previous Topic   Next Topic Topic: Sign on Once, Log in Everywhere

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use