What I am saying is that the documentation on clone() is quite
explicit about what it does and answers the questions that you raised.
"this method creates a new instance of the class of this object and
initializes all its fields with exactly the contents of the
corresponding fields of this object, as if by assignment; the
contents of the fields are not themselves cloned"
In other words, the object itself is duplicated at a low level by the
VM (allowing it to do things like clone final fields). This has the
effect of copying all primitives and object references. This is a
"shallow" copy because only the references to objects are copied and
not their nested contents.
This is ok if "a class contains only primitive fields or references
to immutable objects" and means that "no fields in the object
returned by super.clone need to be modified." So in this case where
the only field "cacheable" is a primitive it does not need to be set
on the clone.
Because Object.clone() applies to the entire object this behaviour
also applies to all subclasses. Only when a field contains a
reference to a mutable object does the subclass need to worry about
doing a deep copy of that referenced object.
As for RMIInvoker, the remoteMethod field is of type Method which is
effectively immutable and so does not need to be deep copied.
--
Jeremy
On Aug 11, 2006, at 7:53 AM, ant elder wrote:
I'm not sure I understand what you're trying to say? The JavaDoc for
TargetInvoker.clone says "Implementations must support deep cloning".
...ant
On 8/11/06, Jeremy Boynes <[EMAIL PROTECTED]> wrote:
On Aug 11, 2006, at 7:36 AM, ant elder wrote:
> I did wonder about this, doesn't it need to be a deep copy? I don't
> really
> understand the purpose of cacheable, but if its set on the one
> instance
> shouldn't it be also set on the clone? And do subclasses need to
> copy their
> fields? Say the RMI binding was using this abstract class should it
> setting
> the remoteMethod field on the clone?
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html#clone()
And remember deep copy only applies to mutable objects
--
Jeremy
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]