Friday, May 06, 2005

Mutating to Immutable

RFE: Add Immutable types to Java "This proposal is to add an interface to mark a class as immutable (note immutability on a per class basis not a per object basis) and to add immutable and companion mutable classes plus two helper interfaces for conversion to/from immutable and mutable."

Some comments: "...== should map to a.equals(b), as they both must have the same samantics for an immutable class. Remember Immutable objects may not be cloned or copy constructed and implementation details like hash-consing (and pass by reference or pass by value) should be invisible to the programmer."

Near the bottom is a link to PEC - Pattern Enforcing Compiler, "A pattern enforcing compiler™ (PEC™) allows classes to be marked as having a given design pattern, e.g. Singleton. The PEC™ then checks that the marked class conforms to the pattern and issues an error message if it does not, thus the pattern checking is much like type checking. The PECs™ downloadable from this site require no new syntax and therefore they can be used with existing: editors, IDEs, pretty printers, etc. The downloadable PECs™ are extensible and therefore as well as using the supplied patterns a programmer can write their own patterns and have the PEC™ enforce these."

It comes with some existing code knitting patterns such as: Immutable, Value, and Multiple Dispatch.

No comments: