|
The Bathyscaphe logo, a line drawing of
bathyscaphe Trieste
|
Abstract
This article introduces Bathyscaphe, an open-source java library that you can
use to assert that your objects are immutable and/or thread-safe.
The problem
Programmers all over the world are embracing immutability more and more;
however, mutation is still a thing, and in all likelihood will continue being
a thing for as long as there will be programmers. In a world where both
mutable and immutable objects exist side by side, there is often a need to ascertain that an object is of the immutable variety before proceeding to use it for certain purposes. For example, when an object is used as a key in a hash map, it better be
immutable, or else the hash code of the key may change, causing the map to
severely malfunction.
Furthermore, when an object is not immutable, there is often the need to ascertain that it is at least thread-safe before sharing it between threads, otherwise there will be race conditions, with catastrophic results.
Note that when any of the above goes wrong, it tends to be a bug which is very difficult to troubleshoot.