From Java 1.6 Collection Framework documentation:
Collections that do not support any modification operations (such as
add,removeandclear) are referred to as unmodifiable. [...] Collections that additionally guarantee that no change in the Collection object will ever be visible are referred to as immutable.
The second criteria confuses me a bit. Given the first collection is unmodifiable, and assuming that the original collection reference has been disposed away, what are the changes that are referred to in the second line? Is it referring to the changes in the elements held in the collection ie the state of the elements?
Second question:
For a collection to be immutable, how does one go about providing the additional guarantees specified? If the state of an element in the collection is updated by a thread, is it sufficient for immutability that those updates in the state are not visible on the thread holding the immutable collection?
newCol = oldCol.add("element")will produce new collection that is copy of old one with 1 more element, and all references to theoldColwill still point to the same unchanged old collection.