aspose file tools
The moose likes Beginning Java and the fly likes How to define immutable object? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How to define immutable object?" Watch "How to define immutable object?" New topic
Author

How to define immutable object?

David Eason
Greenhorn

Joined: Oct 31, 2001
Posts: 14
The article Understanding that parameters are passed by value and not by reference ended this way:
<blockquote>
What if you want to disallow changes to the Point object in methods such as modifyPoint ? There are two solutions for this:

  • Pass a clone of the Point object to the modifyPoint method.

  • Make the Point object immutable.


  • </blockquote>
    My question is, how do you make an object "immutable"?
Rikard Qvarforth
Ranch Hand

Joined: Jul 10, 2001
Posts: 107
Hi, if you make the method signature
"final public static void modifyPoint(final Point pt, int j)"
then the method cant change the copy of the object reference. But if you have methods in the object class that changes members within the object the final key word dosent protect that, that is if you call these methods in the "modifyPoint()" method (i think )
excuse me for my bad english
hope it helps
Rille
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to define immutable object?
 
Similar Threads
Career Opportunities for J2EE Experts in Boston, MA!
Automatic Installation of 100+ Open Source Projects for Java Developers
Dropdown list
Crate an Immutable List?
How to make gc-able?