ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: Implementing the Clonable interface in a task
Date Mon, 12 Aug 2002 18:24:45 GMT
In Java, yes... Standard C++ introduced co-variant return types, which
allows to change the return type of a virtual method of a base class, as
long as the new return type 'isinstanceof' the old return type (to use the
right Java keyword). The real problem with clone is not so much that it
returns an Object, but that it's part of Object, and protected, instead of
being part of the Cloneable interface. Everybody deplores this, but it
cannot be changed, in order not to break backward compatibility.

Using an explicit copy-constructor (not always applicable, since requires to
know the actual type of the object), or extracting the CVS state class so it
can be passed around, are all good suggestions. --DD

-----Original Message-----
From: karl_schnaitter.consultant@peoplesoft.com
[mailto:karl_schnaitter.consultant@peoplesoft.com] 
Sent: Monday, August 12, 2002 12:54 PM
To: Ant Developers List
Subject: Re: Implementing the Clonable interface in a task


James Lee Carpenter wrote:
>>>>>>>>>>>>>
I have been away from java for a year or so.  Can anyone remind me why the
clone method's return type is object instead of the type of object
being cloned?  Isn't it a bit sloppy to require casting the cloned object?
>>>>>>>>>>>>>

When a subclass overrides a function definition, it needs to match the
return type in the superclass, so when you override Object.clone(), (whose
return type is Object, of course) your return type must be an Object.

-Karl




--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message