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 }
const
, not exactly what you want, but near.final
keyword. If an object's state is all final, and the classes (e.g. string, primitives, wrappers) that comprise its members all have final state, then your object is very likely immutable. That is built-in to the language.