4. Clone sample.

Listing 4. Clone sample.


public Object clone() {
  try {
    MyClass result = (MyClass) super.clone();
    result.insets = (Insets) insets.clone();
    // result.dimension = (Dimension) dimension.clone();
    result.dimension = new Dimension(dimension); // SLICE?
    borderLayout = new BorderLayout(
      borderLayout.getHgap(), borderLayout.getVgap());
    result.array = (int[])array.clone();
    result.vector = (Vector) vector.clone();
    for (int i = 0; i < vector.size(); ++i) {
      result.vector.setElementAt(
        ((SomeType) vector.elementAt(i)).clone(), i);
    }
    return result;
  } catch (CloneNotSupportedException e) {
    return null; // never invoked
  }
}