Skip to main content
be more specific
Source Link
Ruudjah
  • 558
  • 1
  • 5
  • 11

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

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 }

Why do mainstream OO languages not have immutability built-in?

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.

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

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 }

Post Closed as "Duplicate" by gnat, CommunityBot, Doc Brown, Bart van Ingen Schenau
Fixed grammar in title.
Link
user22815
user22815

Why don't havedo mainstream OO languages not have immutability built-in?

Source Link
Ruudjah
  • 558
  • 1
  • 5
  • 11

Why don't have mainstream OO languages immutability built-in?

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.