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

RFE: Please have Shape extend Cloneable and mandate public clone()

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.1
    • client-libs
    • 2d
    • generic
    • generic



      Name: ddT132432 Date: 11/26/2001


      java version "1.3.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
      Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)

      This is an extension of Bug #4106105, which is "closed, fixed".

        Every Sun-created java.awt.Shape implementation except for java.awt.Polygon
      defines a public clone() method. Since it would be incredibly beneficial (and
      almost expected) to be able to copy arbitrary Shape objects, I suggest having
      the Shape interface mandate a
      public Object clone();
      method to be overridden by the implementation.

        You're almost there in that all but one of the known implementations do this
      already. As mentioned above the only oddball is Polygon, but here's the method
      that could be dropped in Polygon to make this idea work:

      public Object clone()
        {
        final Polygon copy = (Polygon) super.clone();
        final int[] x = new int[this.xpoints.length];
        final int[] y = new int[this.ypoints.length];
        System.arraycopy(this.xpoints, 0, x, 0, x.length);
        System.arraycopy(this.ypoints, 0, y, 0, y.length);
        this.xpoints = x;
        this.ypoints = y;
        return copy;
        } // ends clone(void)
      (Review ID: 136102)
      ======================================================================

            flar Jim Graham
            ddressersunw Daniel Dresser (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: