Name: rmT116609 Date: 09/09/2004
A DESCRIPTION OF THE REQUEST :
java.util.Collection is the parent to all Collection classes and exports read and write operations to the dataset.
Because there is no const in java there is no way to make collections readonly at compile time, at runtime it is possible to use http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#unmodifiableCollection(java.util.Collection) to enforce the contract but only when the application fails its clear that there is a problem.
By adding a super interface to Collection that only exports: contains(Object) containsAll(SuperCollection) equals hashcode isEmpty() iterator() size() toArray()
Where iterator might also be a superversion without the remove method.
Compiletime support for immutable collections
EXPECTED VERSUS ACTUAL BEHAVIOR :
Will give a compiletime error instead of a runtimeerror when mutating an immutable collection.
Currently no support is available
---------- BEGIN SOURCE ----------
public void shouldntChangeData(Collection c)
c.add(something); //there is no way to enforce this at compile time
public void cantChangeData(ImmutableCollection c)
c.add(something); // method .add is not avaialble on the interface so a compiletime error
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use an allternative collections framework that does support this.
(Incident Review ID: 302408)