Hi; I'm trying to understand the rationale of some of the implementations of
Cloneable in the OpenJPA codebase.
Take, for example, the clone() method in SchemaGroup.java, and its helper
methods:
public Object clone() {
SchemaGroup clone = newInstance();
clone.copy(this);
return clone;
}
/**
* Create a new instance of this class.
*/
protected SchemaGroup newInstance() {
return new SchemaGroup();
}
/**
* Copy cloneable state from the given instance.
*/
protected void copy(SchemaGroup group) {
// Method which actually does the copying
}
If clone() had been written to simply call super.clone(), there would be no
need for a newInstance() method, and, depending on the circumstances,
potentially no need for a copy method.
I suspect there was a good reason for this, but it's tripping me up in a few
places when I'm subclassing.
Does anyone know the history here? Would a set of patches be considered to
rectify this behavior and fall back on the more common super.clone()
behavior?
Best,
Laird