Clonable vector with deep-copy semantics.

EFFECTIVE JAVA
Enhancing container classes with deep-copy semantics
Steve Ball
Listing 2. Clonable vector with deep-copy semantics.


public class ClonableVector extends Vector implements Clonable {
  public ClonableVector() { super(); }
  public ClonableVector(Collection c) { super c; }
  public ClonableVector(int initialCapacity)
    { super(initialCapacity); }
  public ClonableVector(int initialCapacity, int capacityIncrement)
    { super(initialCapacity, capacityIncrement); }

  public Object clone() {
    ClonableVector clone = (ClonableVector) super.clone();
    for (int i = 0; i < clone.elementCount; ++i)
      clone.elementData[i] = GeneLab.clone(clone.elementData[i]);
    return clone;
  }
}

Featured

Most   Popular
Upcoming Events

AppTrends

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.