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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
