Is this way of using clone
correct? I am getting a runtime error every time. Also can anybody suggest a way to write copy constructor in this class?
public class Pair {
final StringBuffer x;
final StringBuffer y;
public Pair(StringBuffer x, StringBuffer y) {
this.x = x;
this.y = y;
}
public StringBuffer getX() {
return x;
}
public StringBuffer getY() {
return y;
}
public Pair clone() {
Pair p = new Pair(new StringBuffer(), new StringBuffer());
try {
p = (Pair) super.clone();
} catch (CloneNotSupportedException e) {
throw new Error();
}
return p;
}
}