T
Thomas G. Marshall
Chris Uppal coughed up:
Huh, you've raised my interest in this example. To what are you referring
re: StringBuffer? (I honestly don't know---sounds intriguing)...
Well put.
Thomas said:Does anyone know why the java designers didn't make every object
shallow-cloneable by default?
I'm coming late to this thread, but FWIW I think this is simply an
error in the Java design. Remember that it comes from the same
timeframe as 'synchronized' StringBuffer [...]
Huh, you've raised my interest in this example. To what are you referring
re: StringBuffer? (I honestly don't know---sounds intriguing)...
and many other design errors (or sub-optimalities).
I think an argument could be made that clone() /shouldn't/ be exposed
by default, on the grounds that the semantics of copying are
complicated and context-dependent (so one size doesn't fit all), and
that the clone() peroration should therefore be something you
opt-into when (and only when) you have understood what copying means
for some object.
The problem with that argument is that it (or something more-or-less
similar) could also apply to Object.equals() and in fact all of the
other methods of Object (except maybe toString()).
Well put.