aspose file tools*
The moose likes Java in General and the fly likes final vs immutable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "final vs immutable" Watch "final vs immutable" New topic
Author

final vs immutable

Rahul Kakkar
Ranch Hand

Joined: Apr 17, 2005
Posts: 70
i read in one of the HF series that in java, the value of a final variable can be changed unless its immutable! can someone explain the meaning of that statement and the difference between the two?
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
We are talking about Object fields here, not primitives. When you have a field declared as final, the reference will not change. It will always point at the same Object. However, if the Object is not immutable, the methods on it (or the Object's visible fields) can be used to change the Object itself - it is the same Object, but its properties have been changed. With an immutable Object, no method call would change the Object's properties, and no non-final fields would be visible.

Does that take away any shred of clarity you still had on the subject?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: final vs immutable
 
Similar Threads
the difference of immutable and final
Why classes are declared final.
Manipulating final variable
Is it possible?
Immutable classes