Type-based Object Immutability with Flexible Initialization
We present a type system for checking object immutability,
reference immutability, and class immutability in an open or closed world.
In order to separate object initialization from object constructors (which is
often needed in practice), immutable objects are initialized in lexically
scoped regions. The system is simple and direct; its only
type qualifiers specify immutability properties. No auxiliary annotations,
e.g., ownership types, are needed, yet good support
for deep immutability is provided. To express object confinement, as required
for class immutability in an open world, we make use of qualifier
polymorphism. The system has two versions: one version with explicit
specification commands that delimit the object initialization phase, and one
version where such commands are implicit and inferred. In the latter version,
all annotations are compatible with Java's extended annotation syntax, as
proposed in JSR 308.