Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5099784

(coll) Readonly superinterface for java.util.Collection

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 1.4.2
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description



      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.


      JUSTIFICATION :
      Compiletime support for immutable collections

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Will give a compiletime error instead of a runtimeerror when mutating an immutable collection.
      ACTUAL -
      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.
      Bytecode rewriting.
      (Incident Review ID: 302408)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              rmandalasunw Ranjith Mandala (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: