Talk:Immutable object

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Java (Rated Start-class, Low-importance)
WikiProject icon This article is within the scope of WikiProject Java, a collaborative effort to improve the coverage of Java on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Start-Class article Start  This article has been rated as Start-Class on the project's quality scale.
 Low  This article has been rated as Low-importance on the project's importance scale.


there is an error: ImmutableCart is immutable only if elements of the list are themselves immutable. Otheriwse, you copy the list allright, but you share the elements with the caller, so he can mutate them as he pleases. —Preceding unsigned comment added by (talkcontribs) 18:40, 19 November 2005

I disagree. It depends on what you consider part of the "ImmutableCart" object. I consider an "ImmutableCart" object to contain only its fields, i.e. the reference "items". Under this definition, "ImmutableCart" is indeed immutable. --Spoon! 09:03, 18 March 2007 (UTC)
Wouldn't this imply that the Cart class is immutable too? I.e. the 'items' reference never changes (although its contents may change). Zedoo (talk) 18:28, 16 August 2008 (UTC)

I changed all references to vector in the C++ example to std::vector, as the C++ example would presumably be in a header file and it is generally considered bad style to include a global using namespace directive in a header file. I think it's very important for code examples to exhibit good style even if that makes them a little more verbose. - Zixyer 02:24, 19 December 2005 (UTC)

why does defensive copying link to object (computer science) which has no information as to what "defensive copying" means probably a mistake, can somebody correct? --Alex 11:10, 30 December 2005 (UTC)

I changed the defensive copy redirect to go to Object copy instead, which talks about defensive copying.Tim Dean 22:07, 31 December 2005 (UTC)

List to Array to List?[edit]

I'm not a C# guy so I was afraid to make the change myself, but does anyone else see anything wacky about ImmutableCart's constructor? I checked the docs and it looks like List has a constructor that takes a collection as an argument, presumably creating a new list containing the same objects as the old one.

Is there a good reason why the example takes the input List, turns it into an array, then turns it into a new List? Guess I'll just make the change... tfrey 21:31, 14 April 2008 (UTC)

Because it's not C# but Java, and List is (last time I checked) not a class and cannot be instantiated. I'm reverting the change. -- Taku (talk) 11:53, 4 May 2008 (UTC)
But wouldn't Collections.unmodifiableList(items) be better in both cases? -- (talk) 14:57, 14 June 2008 (UTC)

No, because Collections.unmodifiableList(items) doesn't create a copy of a list. items.toArray(), on the other hand, gives a copy of an array (not the underlying array.) -- Taku (talk) 20:55, 14 June 2008 (UTC)

Need for disambiguation[edit]

"Mutability" is also used in the biological sciences. E.g. In Voet&Voet, 2011, p3, "Life possesses the properties of replication, catalysis, and mutability." (talk) 16:02, 20 January 2011 (UTC)

Error in c++ example[edit]

The first example in the c++ is not fully immutable. By returning a reference in the non-const getItems() you allow the priovate data to be edited. see my example on ideone: This function needs to either return a copy or a const reference, then the function marked as const. — Preceding unsigned comment added by (talk) 16:07, 7 April 2014 (UTC)

I'm sure I've heard this word and I know nothing about "programming"[edit]


immutable (not comparable)

  Unable to be changed without exception.
       The government has enacted an immutable law.

From Wikipedia, the free encyclopedia

 (Redirected from Immutable) (talk) 10:06, 6 September 2014 (UTC)