2025-06-04

Immutability Assessment

In languages like Java and C#

Abstract

The need is identified for programmatically ascertaining the immutability of certain objects used in situations where they are expected to be immutable. The technicalities of immutability assessment are examined. A mechanism is described for achieving it.

The Problem 

Raise your hand if you have ever had to troubleshoot a bug that manifested itself in mysterious ways, defied rational explanation, tenaciously evaded detection, made you rage impotently at the absurdity of the observed behavior, and after much weeping and wailing and gnashing of teeth, turned out to be due to one of the following reasons:

1. Inadvertently mutating an object that has been added as a key in a hash map.

2. Inadvertently mutating an object that has been passed to another thread.

in general: