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

The List Interface should extends Cloneable to ease list cloning

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.3.0
    • core-libs



      Name: stC104175 Date: 06/30/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)


      I request a small feature list enhancement to the abstract List interface of
      the Collection Framework.

      The problem occurs when one whishes to clone a list through the abstract List
      interface.
      This is impossible because the List interface doesn't extend Cloneable nor
      redefine the clone method public:
        List l= new LinkedList();
        List l2= (List ) l.clone();
      produce an error "method clone is protected in Object".

      The only way I have found so far is to go to the actual implementation:
        List l2= (List ) ((LinkedList ) l).clone();
      This is not only ugly, but also is in a sense against the Collection framework
      objectives.

      A better alternative would be that List extends Cloneable or "publicize" the
      clone method.

      Thank you for your attention.
      (Review ID: 106736)
      ======================================================================

            jjb Josh Bloch (Inactive)
            stompkinsunw Sean Tompkins (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: