lundi 26 janvier 2015

Why do mainstream OO languages not have immutability on class-level built-in? [duplicate]



This question already has an answer here:




I regularly write classes which can only have immutable instances, much like string.


I am wondering why Java or C# or VB.NET don't have immutability built-in into the language? That way, I can communicate immutability better to my fellow programmers and also make assumptions about state in the class.


For instance: immutable class Foo { public string Name { get; set; } //compile error: mutable property on immutable class }





Aucun commentaire:

Enregistrer un commentaire