...
This code prints: "246", which shows that the value of the supposedly immutable BigInteger bi
has been changed.
OBJ01-J. Limit accessibility of fields points out that invariants cannot be enforced for mutable objects. TSM03-J. Do not publish partially initialized objects describes object construction and visibility issues specific to mutable objects, and CON50-J. Do not assume that declaring a reference volatile guarantees safe publication of the members of the referenced object and CON52-J. Document thread-safety and use annotations where applicable discuss some concurrency issues associated with mutable objects.
This example is particularly important because the BigInteger
type has several useful cryptographic applications.
...