static A shallowClone(A o) {
ret (A) shallowClone_impl(o);
}
static A shallowClone(A o, A emptyClone) {
ret copyFields(o, emptyClone);
}
static O shallowClone_impl(O o) {
if (o == null)
return o;
if (o instanceof List)
ret cloneList((List) o);
if (o cast Map) ret cloneMap(o);
if (o instanceof String || o instanceof Number || o instanceof Boolean)
return o;
if (o instanceof Object[]) {
Object[] l = (Object[]) o;
ret l.clone();
}
// clone an arbitrary custom object
O clone;
if (o cast IMakeEmptyClone)
clone = o.makeEmptyClone();
else
clone = nuEmptyObject(o.getClass());
//print("Cloning custom: " + o);
copyFields(o, clone);
ret clone;
}